- Home /
spell hit rigidbody
i made this spell casting script and i want it to hit other rigidbodys how do i do that here is the scrip
var spell : Transform;
function Update ()
{
if(Input.GetButtonDown("Fire2"))
{
var magic = Instantiate(spell, GameObject.Find("spawnPoint").transform.position,
Quaternion.identity);
magic.rigidbody.AddForce(transform.forward * 2000);
}
}
here is the script on the fireball
var ParticlePrefab : GameObject;
function OnCollisionEnter(collision : Collision)
{
: Instantiate(transform.position, transform.rotation, ...);
Instantiate(ParticlePrefab, transform.position, transform.rotation);
Destroy(gameObject);
}
Please, format your script. It's quite difficult to read, as you may have seen. Click the spot where you want to place your code, then click the button with binary on it. Then copy/paste. This will improve your chances to get the right answer. Good spelling doesn't hurt too! ;)
Oh, and I retagged your question, to somewhat more suitable tags. Despite its frequency, "help" is not a good tag.
Answer by Meater6 · Jan 14, 2013 at 08:28 PM
Ok, I think I noticed a few problems in your scripts.
Instantiating a transform makes an empty GameObject. You do this in your firing script. I'm pretty sure thats not what you want to do. Instantiate a GameObject Instead like so:
var spell : GameObject;
and then latervar magic = Instantiate(spell, spawner.position, spawner.rotation);
.You use GameObject.Find, without assigning it. Its much more efficient (in CPU cycles), to have
var spawner : Transform;
, instead of "GameObject.Find("spawnPoint")". Even if you ever have to find a GameObject, its preferable to use GameObject.FindWithTag.You use Quaternion.Identity instead of the rotation of the spawner. This makes it always look forward, even if say, whatever is using the spell, is facing sideways.
I see "`: Instantiate(transform.position, transform.rotation, ...);`" I hope thats not your real script, because that will most certainly not work.
I think those are bugs that are in your script. I may have missed some, unfortunately, as there are many. I do hope you get your script working right.
Good Luck!
it works now it was something i have done on the rigidbody i was shooting and thanks for help. by the way can you help me with a spell system like dishonered
thank you for help and i found out what was wrong i was on the rigidbody i was shooting. by the way can you help me with a spell system like dishonored