- Home /
Question by
fintyaraXX · Jun 03, 2016 at 06:14 AM ·
rigidbodybullet
Shooting with the maneuvering of the ship
Hello! Faced with a problem when you create a space shooter . The ship moves with the help of physics. The bullet , too . With the active maneuvering bullets fly in the "wrong" side
Help me please!
// Fire code
GameObject temp;
temp = (GameObject)Instantiate(_BulletPref, PivotShoot.position, PivotShoot.rotation);
temp.GetComponent<Rigidbody>().velocity = gameObject.GetComponent<Rigidbody>().velocity;
//Bullet movement code
void Start()
{
if (GetComponent<Rigidbody>())
GetComponent<Rigidbody>().AddRelativeForce(Vector3.forward * speed * Time.deltaTime);
}
// Ship movement code
if (_stateV > 0)
{
MyRigid.AddRelativeForce(Vector3.forward * curThrust * Time.deltaTime, ForceMode.Force);
if (MyRigid.velocity.magnitude > 0 && MyRigid.velocity.magnitude > MyShip.maxSpeed)
MyRigid.velocity = MyRigid.velocity.normalized * MyShip.maxSpeed;
}
333.jpg
(18.4 kB)
Comment
Your answer
Follow this Question
Related Questions
Realistic Bow and Arrow Physics? 2 Answers
how to rotate to face camera point in 2D 2 Answers
Issue with Bullet Movement shooting 0 Answers
move Object without coroutine 0 Answers
Bullet Sometimes Go Throw Object 0 Answers