- Home /
Want to add ship's velocity to Instantiated projectile
Hey all, first Unity project. Loving Unity but the learning curve is fairly thick to someone not used to OOP or C#. I'm rolling my own physics/collision as I don't need the might of Havok in a simple asteroids type shooter, so I cant do any rigid body cheats.
GameObject bullet = Instantiate(BulletType,transform.position,transform.rotation) as GameObject; Component bVel = bullet.GetComponent("BulletShoot");
//bVel.velocity += velocity;
Getting this error:
Assets/Code/player.cs(42,27): error CS1061: Type `UnityEngine.Component' does not contain a definition for `velocity' and no extension method `velocity' of type `UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?)
Both the ship code (this firing script is activated in the ship's update code), and the bullet code have a Vector3 "velocity" variable. BulletShoot is the bullet's movement script, and it works until I try and add the ships velocity to bVel in that commented out line.
Not really sure what I'm doing wrong, or how to find an answer. Any ideas?
Thanks, -Chris
Answer by Chrizzle · Mar 24, 2011 at 03:16 AM
Thanks for the pointer Dave, it gave me another error but was part of the solution. I need move BulletShoot into <> for c#. I dont quite understand this and it's caused other wierd artifacts, but it's movin along. Thanks!
BulletShoot bVel = bullet.GetComponent<BulletShoot>();
bVel.velocity += velocity;
Answer by DaveA · Mar 23, 2011 at 07:05 AM
Try
BooletShoot bVel = bullet.GetComponent("BulletShoot");