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 cidmodder · Dec 02, 2010 at 01:57 AM · javascriptgunweaponattackfire

Shooting Pistol and Machine Gun

I have a pistol that shoots but it won't shoot when i Turn it just goes down one axis no matter which way I'm facing.

var newObject : Transform;

function Update () {

if (Input.GetButtonDown("Fire1")) {

Instantiate(newObject, transform.position, transform.rotation);

audio.Play();

}

}

How can I get it to change to shoot where ever i'm facing?

Also how would I change this to where it keeps firing as I hold down the mouse button like a machine gun?

Comment
Add comment · Show 3
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 Rennat · Dec 02, 2010 at 02:05 AM 0
Share

This script is on the character correct? also what script is on newObject?

avatar image cidmodder · Dec 02, 2010 at 03:02 AM 0
Share

The Script is on the character. the new object is.....

//Bullet //how fast does the shot move var speed:float; var damage:int=-1; function Update() { //each frame move forward by speed units per second transform.position.z += speed *Time.deltaTime; }

//gets called when we hit something function OnTriggerEnter(other:Collider) {

//what are we hitting? we are only interested in hitting "enemy" if(other.gameObject.CompareTag("Enemy")) { //send a messege telling the object to take damage

other.gameObject.Send$$anonymous$$essage("OnDamage", damage); //destroy object Destroy(gameObject); } }

avatar image cidmodder · Dec 02, 2010 at 03:04 AM 0
Share

ok i took out the velocity on the bullet script and now the bullets shoot where the gun is pointed but they just sit there

2 Replies

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

Answer by oliver-jones · Dec 02, 2010 at 02:03 AM

Try this:

var projectile : Rigidbody; private var speed = 5;

function Update(){ if(Input.GetButtonDown("Fire1")) {
var instantiatedProjectile : Rigidbody = Instantiate(projectile, transform.position, transform.rotation);

 instantiatedProjectile.velocity =
     transform.TransformDirection(Vector3(speed, 0, 0));

}

Give your object that you are firing a rigidbody (then turn off gravity)

-----OR-----

if could be that you haven't placed your 'firing object' into your camera (thus changing its position with your players)

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 cidmodder · Dec 02, 2010 at 03:00 AM 0
Share

that didn't do it. The pistol does rotate and follow around with the camera. the bullets just dont

avatar image cidmodder · Dec 02, 2010 at 03:29 AM 0
Share

at some point I had made it kinematic and that game me an error. now it works.

avatar image
0

Answer by drfudgemuffin · Feb 15, 2013 at 10:48 PM

rotate the bullet to face forwards that fixed for me

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

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

1 Person is following this question.

avatar image

Related Questions

My gun won't fire. ( Javascript ) 1 Answer

dynamic_bitset.test bit out of bounds 0 Answers

Gun Firing help? 2 Answers

Gun Script glich? 1 Answer

Multiple Animations, Please Help 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