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 M364M4Ncro · Jun 09, 2012 at 11:30 AM · gunshootturrettankshell

firing a shell from a tank turret

hey guys, im trying to have a tank shooting, so a have a tank which has a turret, the end of a turret has an empty object from where i the shell spawns and im using this script:

 public var shellSpawn : Transform;
 public var shell : Transform;
 
 function Start () {
 
 }
 
 function Update () {
 
 if(Input.GetKeyUp("mouse 0"))
 {
     var object = Instantiate(shell, shellSpawn.transform, shellSpawn.rotation);
     
     object.
 }
 
 }

but the problem is that for some reason the shell dosnt allway spawn where its supposed to spawn

here is the code how i rotate my gun:

 public var gunPrefab:Transform;
 private var gun:Transform;
 
 
 function Start () {
 gun = Instantiate(gunPrefab,transform.position,transform.rotation);
 gun.parent = transform;
 
 }
 
 
 
 function Update () {
 
 var temp : Vector3;
 temp.x = Input.GetAxis("Mouse Y") * (-1);
 temp.y = Input.GetAxis("Mouse X") ;
 temp.z = transform.rotation.z;
 
 
 if((temp.x > 0 && gun.localRotation.x > 0.10) || (temp.x < 0 && gun.localRotation.x < (-0.10)))
 {
     temp.x = 0;
 }
 if((temp.y > 0 && gun.localRotation.y > 0.15) || (temp.y < 0 && gun.localRotation.y < (-0.15)))
 {
     temp.y = 0;
 }
 
 
 gun.transform.Rotate(temp);
 }
Comment
Add comment · Show 9
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 ExTheSea · Jun 09, 2012 at 11:43 AM 2
Share

You should check whether the shellspawn maybe is in a collider.

I don't know if this would do something but I would write shellSpawn.position ins$$anonymous$$d of shellSpawn.transform.

Does your tank turret turn. and if yes is the shellSpawn a child of the camera so that it turns with the turret?

avatar image M364M4Ncro · Jun 11, 2012 at 03:39 PM 0
Share

i made shure its not in a colider

my tank turnes, but my shellspawn is a child of my turet, which is a child of my tank

avatar image pheash · Jun 11, 2012 at 04:37 PM 0
Share

I had a similar problem with a mortar weapon, and i found the problem was in my shell script. check whether you are adding some movement there. you could also temporarily reduce the speed at which the game runs to see exactly where it is spawned and what is happening. use Time.timeScale = 0.3;

avatar image M364M4Ncro · Jun 11, 2012 at 05:56 PM 0
Share

i think that movement is not the issue, i tried it without movement

avatar image ExTheSea · Jun 12, 2012 at 01:28 PM 0
Share

Where does it spawn sometimes. I mean is just rotated around or is it maybe sometimes behind the tank or what?

...and is it random? If you don't move and shoot two times are the two shells spawning on the same position/rotation?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bazsee · Jun 12, 2012 at 09:43 AM

Try:

 var object = Instantiate(shell, shellSpawn.transform.location + shellSpawn.transform.forward, shellSpawn.rotation);
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 Bazsee · Jun 12, 2012 at 09:44 AM 0
Share

of course then the shellSpawn object must be facing in the direction which you want to shoot, so the shell gets instantiated in front of it.

avatar image M364M4Ncro · Jun 12, 2012 at 06:23 PM 0
Share

nope, dosnt help, btw its position, not location

avatar image Bazsee · Jun 12, 2012 at 06:29 PM 0
Share

ah sry...i was at work and wasn't concentrating on the answer

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

6 People are following this question.

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

Related Questions

Gun Turret will not Shoot. 1 Answer

rotating a tank turret while the tank is rotating 3 Answers

first Gun fires not well 2 Answers

Help With Turret 1 Answer

Rigidbody of empty bullet shell collision problem. 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