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 SebastianTarrant · Oct 07, 2020 at 02:39 PM · 2d gameshootingtutorialtop down shooter

I need help with a top down 2d shooter

I've followed this Brackeys tutorial to a tee: https://www.youtube.com/watch?v=LNLVOjbrQj4&t=1s

But when I shoot, the bullets don't appear on screen. They show up in the Hierarchy but not on screen. Would really appreciate the help! Here is my code:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Shooting : MonoBehaviour { public Transform FirePoint; public GameObject bulletPrefab;

 public float bulletForce = 20f;

 void Update()
 {
    if (Input.GetButtonDown("Fire1"))
     {
         Shoot();
     }
     
 }

 void Shoot()
 {
     GameObject bullet = Instantiate(bulletPrefab, FirePoint.position, FirePoint.rotation);
     Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
     rb.AddForce(FirePoint.up * bulletForce, ForceMode2D.Impulse);
 }
 

}

Comment
Add comment · Show 10
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 Klarzahs · Oct 07, 2020 at 04:39 PM 1
Share

Hi. Your instantiating code looks fine afaik. Does your bulletprefab have a model? Is the position correct/is it off screen?

avatar image SebastianTarrant Klarzahs · Oct 07, 2020 at 04:48 PM 0
Share

Hi. The bullet can't be on screen at the beginning. If you quickly scroll through the link I put at the top (or go somewhere around the 10 $$anonymous$$ mark) you'll see that it has to be a prefab and then gets referenced in the code. I saw some people in the comments saying that this didn't work anymore, but saw no answers. Do you recon that unity has changed something?

avatar image Klarzahs SebastianTarrant · Oct 07, 2020 at 09:52 PM 1
Share

Dont know about a change, can you upload your project somewhere and link it? I'll have a look at it tomorrow, that would probably be the easiest way

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by SebastianTarrant · Oct 08, 2020 at 05:07 PM

The problem was that the Bullet Prefab didn't have a sprite. So adding one fixed the whole problem. Hope this can help someone else!

Comment
Add comment · 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
0

Answer by l3mon · Oct 07, 2020 at 05:33 PM

When they are in the hierachy, they're there - which is the good news.

Simple way to check would be to select the object and press 'F' in the editor to focus on the object. Otherwise, you could also just check the transform in the editor or in the debugger when you instantiate.

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 SebastianTarrant · Oct 07, 2020 at 07:42 PM 0
Share

Hi. Focused on the bullet and it's "there" on screen but just flies out of "view" of the main camera. Still can't see it though. Could you please elaborate your ideas? Thanks

avatar image SebastianTarrant · Oct 08, 2020 at 05:08 PM 0
Share

The problem was that the Bullet Prefab didn't have a sprite. So adding one fixed the whole problem.

avatar image l3mon SebastianTarrant · Oct 08, 2020 at 06:31 PM 0
Share

Glad you worked it out!

avatar image
0

Answer by enestelli · Oct 07, 2020 at 08:03 PM

Could the up of your Firepoint point to the z-axis? Maybe the bullet you created moves in the z axis and is therefore we can't see it? Can you try new Vector3 (0,1,0) or shortly Vector3.up instead of FirePoint.up?

Comment
Add comment · Show 5 · 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 SebastianTarrant · Oct 07, 2020 at 08:59 PM 0
Share

Hi. I wouldn't think so as the fire point is where the bullet originally spawns and is a game object in itself. Unless you think changing this would work anyway?

avatar image enestelli SebastianTarrant · Oct 07, 2020 at 11:34 PM 0
Share

I am not sure. Could you try it?

avatar image SebastianTarrant enestelli · Oct 08, 2020 at 08:39 AM 0
Share

Tried it and it didn't work

avatar image SebastianTarrant · Oct 08, 2020 at 05:08 PM 0
Share

The problem was that the Bullet Prefab didn't have a sprite. So adding one fixed the whole problem.

avatar image enestelli SebastianTarrant · Oct 08, 2020 at 07:27 PM 0
Share

Happy for you!

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

189 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 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 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 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 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 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 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 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 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

How to make shooting in top down 2d shooter game? Unity 2d 1 Answer

Shooting a bullet object toward the mouse position in a 2D. 1 Answer

How do I stop a 2D projectile when it reaches a point 3 Answers

How to remove "lines" when using noise setting with cinemachine virtual camera 2 Answers

Target Lookat not working . I want Z axis to rotate only. 2 Answers


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