Author Topic: Help with spawning projectile via function?  (Read 2607 times)

I'm trying to spawn a projectile by using a function but I can't seem to get it to work properly. I know about:
Code: [Select]
%proj = new Projectile()
{
dataBlock = 'name';
initialPosition = %position;
initialVelocity = 3;
client = %player;
};
I just have it set up so that when the function is called, the current item is removed from the inventory, and then I want a projectile to spawn like it is being thrown from the player (projectile spawns where player is looking) but I don't think I set it up right so I deleted everything and starting over lol.

Code: [Select]
%proj = new Projectile()
{
dataBlock = 'name';
initialPosition = %position;
initialVelocity = 3;
client = %player;
};
//Everytime you are going to "add" something to the world manually
//you have to call this
missioncleanup.add(%proj);




^ while that is good practice, that is not the problem, but you are missing sourceObject too

What are you exactly using to make the projectile?

It did solve my spawning-in-the-world issue. I have more issues though :P The projectile spawns sideways, and I think in the "middle" of the world, not the player. I know it's probably my variables(not set up right/carrying over?), and not being able to get/set the position on/from the player because I'm [still learning] dumb.

Initial velocity is a 3 field vector (Vector3F) (X Y Z), your field is only an integer. Always remember that velocity is a direction of speed, stating the speed in an integer will not make sense.

What direction to do you want the projectile to go to?
« Last Edit: September 29, 2017, 01:54:10 AM by Kyuande »

keep in mind that if you're spawning a projectile from the player, you'll want to rotate the velocity vector relative to the player's eye vector (ask visolator for help on this)

if you don't the projectile will always go in a certain direction regardless of which way you're player is facing.

Initial velocity is a 3 field vector (Vector3F) (X Y Z), your field is only an integer. Always remember that velocity is a direction of speed, stating the speed in an integer will not make sense.

What direction to do you want the projectile to go to?
Thanks :) What I posted above was actually just an example from somewhere, just wanted to make sure people know what I'm after. But I did have just an integer so I will look up my references on Vector3F stuff.

And what PhantOS said, I want the projectile to be spawned relative to where the player is facing, "forward".

keep in mind that if you're spawning a projectile from the player, you'll want to rotate the velocity vector relative to the player's eye vector (ask visolator for help on this)

if you don't the projectile will always go in a certain direction regardless of which way you're player is facing.
Yea it's pretty wonky atm lol. Thanks for the help. I'm gonna see if I can find some more examples on the eye vector cuz my reference sites are not helping much.

Getting the eye vector is super easy because is already a function. Another vector is forward vector, easy for pushing people forward when you multiply it.

I will create a few velocity examples when I get back on later if no one does

vector math is a bitch by default

Examples of velocity you can use (for a projectile) - the examples may or may not be correct or might be overcomplicated, but try the 2nd example and see if that's what you are finding:

//This is an example of how to fling a projectile in a direction the target is (homing) using ImageName::onFire(%image, %player, %slot) - Will have to create own vars other than %player
%vec = vectorScale(vectorNormalize(vectorSub(Vector3F %posA, Vector3F %posB)), int %scale);
//example: vectorScale(vectorNormalize(vectorSub(%player.getPosition(), %targetPlayer.getPosition())), 80);

//Example of shooting from the muzzle's velocity using ImageName::onFire(%image, %player, %slot)
%vec = vectorScale(%player.getMuzzleVector(%slot), %image.projectile.muzzleVelocity);