Fire ball script?

Okay so i need a VERY simple fire ball script. too shoot from the middle of my character and be able to reach some distance i try ed to make my own script and epically failed

This is directly from the scripting reference under “instantiate”

// Instantiate a rigidbody then set the velocity

var projectile : Rigidbody;

function Update () {
// Ctrl was pressed, launch a projectile
if (Input.GetButtonDown("Fire1")) {
// Instantiate the projectile at the position and rotation of this transform
var clone : Rigidbody;
clone = Instantiate(projectile, transform.position, transform.rotation);

// Give the cloned object an initial velocity along the current
// object's Z axis
clone.velocity = transform.TransformDirection (Vector3.forward * 10);
}
}

tornado twins tutorial on youtube actually covers this about half way thru.

used that to help the guy but it shoots straight up, tried to get it to go straight but avas no luck.

yea but about tornado is they use a basic 2.6 FPC im using a model with custom walking scripts so they way they do it wont work i just need something to put on my character to left click and a fire ball will shoot

and tool i tryed that it jsut shoots under my feet

Anyone???

Shouldn’t shoot straight up or under your feet. The velocity is forward. You may be having problems with it colliding with your character’s collider. Take a look at Ignore Collision in the scripting reference. You can set it to ignore the player’s collider. Alternatively, place an empty game object in front of or the the right or left of your player and make that your launcher (with no collider).

I have NO clue what you just said well if anyone else or you can explain it fire away ill be on after school tommarow

OK, if your fireball prefab has a collider (which I assume it does) and your character or tank or whatever is shooting the fireball has a collider, they can interfere with each other. Colliders are the component of a game object that allow it to interact with another game object. This is fine when you want the fireball to hit something and blow it up, not fine when it hits the game object that’s firing it.

If you’re shooting the fireballs from a first person controller, attach the above script to the camera (which is a child of the player object). That way you can aim where your character looks. Or, as I mentioned, create an empty game object and add it as a child of the camera a bit off center so that the fireballs aren’t shooting directly down your line of sight. And more than likely you’ll still need to use Ignore Collision.

If none of this makes sense, then you’re probably missing some of the basics of Unity. You’ll need to get these concepts under your belt if you want to develop games on this platform. The shooting script above has several concepts that you’ll use over and over again so you need to understand it.

I would suggest you look at Will Goldstone’s tutorial videos on www.unity3dstudent.com Start with the “essentials” and work your way through. He’s probably the best teacher for basic understanding of Unity.

Lol… i tryed all of that

You used IgnoreCollision? tool55 has quite nicely explained the fact that your fireball is most likely colliding with your player, and provided you with the solution. From your responses, I have no clue whether or not you have attempted to use IgnoreCollision.

But why is it spawning UNDER my feet? you sure that would be a collision??

It could be. When an object starts inside of another object, the physics happen too fast for you to see it moving away from the player, giving the impression of it being spawned away from (in your case beneath) the player.

then spawn it from a GameObject

So put it in a game object infront of a character?

Okay i got it too shoot out, now how would i go about the animation? so he razes his hand when it shoots???

My best guess is to play an animation when you press your fire button :slight_smile:

If you read the documentation, you would know how to do all of this.

Here you go, have a blast: http://unity3d.com/support/documentation/

Okay tight

i tried that script but it has an error with the first ‘var’. Any advice?