Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Hogge · Mar 01, 2014 at 09:27 PM · physicspositionspawnbullet

Bullets spawn behind plane?

So I've completely reconsidered the way I'll make my scrolling shooter. I was originally planning on making it with simple 2D gameplay, but then I realized it'll be quicker if I make my Starfox clone straight away.

So I managed to get most stuff working, I just have one problem, which I can't get around. I've managed to make the plane fly, I managed to get it to shoot in the direction it's facing. All fine and well. Except that the bullets seem to spawn behind the canon prefab. You can see the problem in the video below: Video Link Anyone know what the problem is? Here's the code for the cannon that instantiates the bullet:

 using UnityEngine;
 using System.Collections;
 
 public class PlayerCannon : MonoBehaviour {
     public Rigidbody bullet;
     public float velocity = 10.0f;
     public Transform Player;
 
     // Use this for initialization
     //void Start () {
     
     //}
     
     // Update is called once per frame
     void Update () {
         if (Input.GetButton ("Fire1")) {
             Rigidbody newBullet = Instantiate (bullet, Player.position, Player.rotation) as Rigidbody;
             newBullet.AddForce(transform.forward*velocity, ForceMode.VelocityChange);
                         
         }
     }
 }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lo0NuhtiK · Mar 01, 2014 at 09:53 PM 0
Share

What are you assigning to the Player variable? The ship, or a spawnpoint transform ? If it's the ship, then you need to either change it to a spawnpoint transform that you position where you want it to spawn at, or offset the spawn position (Player.position) to spawn it where you want it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunnybomb7670 · Mar 01, 2014 at 09:59 PM

An alternate way to position you're bullets properly is to store a gameObject, an empty one on you're ship and position it to where you want you're bullets to come from, then instead of instantiating it from the ships position, instantiate it from the position of the empty gameObject.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Hogge · Mar 01, 2014 at 10:03 PM 0
Share

It might not be clear from the code, but that's precisely what I'm doing. I've set the Player variable to my two canon prefabs. That's why you can see the plane firing two bullets.

avatar image Lo0NuhtiK · Mar 01, 2014 at 10:20 PM 0
Share

$$anonymous$$aybe your ship is outrunning the bullets. Slow the ship way down and fire a few rounds to see where they spawn at.

avatar image Hogge · Mar 01, 2014 at 11:06 PM 0
Share

Yes, I think you're right. The bullets seem to spawn standing still, and then accelerate up to speed. Any way I can make them spawn at their target speed?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Setting a starting position for bullet. 1 Answer

Character Born Position 2 Answers

transform.position in fixedUpdate() different from transform.position in Update(); 1 Answer

Aim helper in realistic sniper game 1 Answer

Transform.Position vs Rigidbody.Position 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges