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 casper2222 · Oct 24, 2013 at 08:54 PM · shooting

what is the wrong,making shoot system?

hello

I want to make shoot system ,i have made a script but the bullet go in one direction only i want the bullet go with the gun in all direction when the gun move

thanks,

using UnityEngine; using System.Collections; public class Shoot : MonoBehaviour { public GameObject bullet; public Transform spawnPoint; public float speed = 50; public float rate = 1; private bool canShoot = true; //-------------------------- //-------------------------- public void ShootBullets(){ //shoot at every rate second(defulat every 1 sec) if(canShoot){ canShoot = false; Invoke("Reset", rate); GameObject bulletClone = (GameObject)Instantiate(bullet, spawnPoint.position, Quaternion.Euler(90, 0, 0)); bulletClone.rigidbody.velocity = (-spawnPoint.up * speed) + rigidbody.velocity; } } //---------------------------- //----------------------------- private void Reset(){ canShoot = true; } }

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

2 Replies

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

Answer by Krey · Oct 25, 2013 at 12:43 AM

I believe the problem is a combination of the answer above and the rotation you are setting. As your code stands, you are setting your rotation as

  Quaternion.Euler(90, 0, 0)

No matter what. That means that -spawnPoint.forward will always be the same direction (the projectile is always spawned in the same rotation / facing).

I think you're going to want to spawn your projectile more like this (EXAMPLE):

 GameObject bulletClone = (GameObject)Instantiate(bullet, spawnPoint.position, FiringWeapon.transform.rotation);
  
 bulletClone.rigidbody.velocity = (-spawnPoint.forward * speed) + rigidbody.velocity;

You're going to need a reference to the weapon firing the projectile (which you'll probably find useful later for other reasons as well).

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 Dave-Carlile · Oct 24, 2013 at 08:55 PM

I believe you want to change this:

 bulletClone.rigidbody.velocity = (-spawnPoint.up * speed) + rigidbody.velocity;


to this:

 bulletClone.rigidbody.velocity = (-spawnPoint.forward * speed) + rigidbody.velocity;

The Transform.forward property points in the direction the object is facing.

Comment
Add comment · Show 2 · 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 casper2222 · Oct 24, 2013 at 10:07 PM 0
Share

it does not work,i want the bullet move with the gun

avatar image Dave-Carlile · Oct 24, 2013 at 11:14 PM 0
Share

What are you setting spawnPoint to? That should be set to the position of the gun.

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

17 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

Related Questions

Shooting 2D - how to fix 1 Answer

Cannon shoots in wrong direction with unrealisic Physic 1 Answer

AirStrike Scripting Help 0 Answers

how to make enemies shoot projectiles towards the players corrent position?(2d game) 0 Answers

How to destroy only one GameObject??? 0 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