|
I have this script `var bulletprefab:Transform; function Update () { }` and I want the bullet to fire forward, but as it stands all it does is give me the error, Assets/scripts/bullet.js(9,42): BCE0023: No appropriate version of 'UnityEngine.Rigidbody.AddForce' for the argument list '(int)' was found. I am new to unity and scripting so im a little confused, an explanation would be appritiated.
(comments are locked)
|
|
About bullets and games there's a few things you should know. If you're making a regular gunbullet, like, lets say from a pistol, then i wouldnt use a mesh/collider to detect if you've hit anything, there's 2 reasons for this.
You can remedy this by using a Raycast, A raycast casts a ray in a given direction and sees if you hit anything, if it does it returns the object that was hit. this can be used instead of the bullet, or you can make the raycast originate from the bullet itself. about your question, the line of code thats giving you the error is this one: you should write it as: instead, thats in c# btw, there should be something equivalent in javascript, here's a link to the documentation: Clicky this help so much, apart from the bullets are now firing upwards instrad of accross. the game is a topdown game and the bullets are firing up. i dont suppose you know why this is?
Oct 26 '11 at 11:38 AM
Tomblade13
thats because the "new Vector3" part of the code point up, a vector is a direction in 3D space, it looks like this: Vector3(x,y,z) so, if you put 2000 in the y spot it will push with a force of 2000 on the y-axis. if you want it to go in another direction, try writing it like this: "new Vector3(2000,0,0)" or "new Vector3(0,0,2000)", you can use negative values as well.
Oct 26 '11 at 11:46 AM
Kacer
I have found a major problem, the bullets fire in the same direction dispite the rotation of the character or spawnpoint.
Oct 26 '11 at 11:54 AM
Tomblade13
try using vector3.forward here's a link to what you can do with vector3 http://unity3d.com/support/documentation/ScriptReference/Vector3.html
Oct 26 '11 at 12:04 PM
Kacer
(comments are locked)
|

Problem is, Transform."2000" isn't a thing. As in, not even slightly. Try using
instead. The rest of it looks pretty much ok, although you might want to put a few more explicit types in there (I don't know why javascript even has the other kind)