Tyz_666
September 9, 2013, 7:13pm
1
var bulletprefab:Transform;
function Update ()
{
if(Input.GetButtonDown(“Fire2”))
{
Instantiate(bulletprefab,GameObject.Find(“SpawnpointA”).transform.position, Quaternion.identity);
bulletprefab.rigidbody.AddForce(transform.forward * 5000);
}
}
This is the script I have. Im trying to make a fireball shoot from a worm, but it needs force. When I press the button for the fireball it has no force, it just sits there, Help? How do I change this to give my rigidbody force?
5000 maybe the reason, have you tried a smaller number? could be that 5000 is out of bounds
also have you had a look at this thread?
Hey guys, I'm trying to put together a Geometry Wars like clone just to become familiar with Unity. Currently I have an orthographic camera set up facing into the positive Z axis. I also have a cube, which is the player, moving around the screen and...
Tyz_666
September 9, 2013, 7:44pm
3
I started with a smaller number at first. And that’s hard to understand
my suggestion is to break down the math to invidual componants and understand what each one does, not be concerned with understanding it all in one gulp for now. programming and math are similar in the fact they are much easier to follow when broken down piece by piece or line by line.
BPPHarv
September 9, 2013, 9:09pm
5
Your code attempts to add force to the source prefab and not the newly created object.
You don’t store the value (GameObject) returned by Instantiate and you need that result to reference the newly created bullet for subsequent calls.
var newBullet : GameObject = Instantiate(bulletprefab,GameObject.Find("Spawnpoi ntA").transform.position, Quaternion.identity);
newBullet.rigidbody.AddForce(transform.forward * 5000);
Tyz_666
September 9, 2013, 10:11pm
6
var before newbullet doesn’t work. it does work without it.
var bulletprefab:Transform;
function Update ()
{
if(Input.GetButtonDown(“Fire2”));
{
bulletprefab : GameObject = Instantiate(bulletprefab,GameObject.Find(“SpawnpointA”).transform.position, Quaternion.identity);
bulletprefab.rigidbody.AddForce(transform.forward * 5000);
}
}
Now it says: Expecting }, found =
It still says it when I get rid of the equal sign.
Tyz_666
September 9, 2013, 10:23pm
7
it also says unexpected token: newbullet. after I relized my mistake and new bullet will work instead of bulletprefab
This is a more complete/correct solution for what you are trying to do.
var bulletPrefab : GameObject;
var spawnPoint : Transform;
function Start()
{
spawnPoint = GameObject.Find("SpawnpointA").transform;
}
function Update()
{
if(Input.GetButtonDown("Fire2"))
{
var bullet : GameObject = Instantiate(bulletPrefab, spawnPoint.position, Quaternion.Identity);
bullet.rigidbody.AddForce(transform.forward * 50);
}
}
Tyz_666
September 9, 2013, 10:35pm
9
MissingFieldException: UnityEngine.Transorm.GameObject
I couldn’t even begin to comprehend this.