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
-1
Question by Triqy · Jan 03, 2014 at 03:50 AM · rotationinstantiatepositionangles

instantiating at different Angles?

I want to be able to instantiate a bullet object on an enemy tank with a specific angle trajectory. This is what I have so far...

 function ShootCannon(){
 
 //this is the position of fire at the muzzle of the tank
 var firePos = Vector3(transform.position.x  + 3.05,transform.position.y + 1.05,transform.position.z);
 
 //this is the bullet creation
 var instance = Instantiate(Bullet, firePos, transform.rotation);
 instance.velocity = transform.TransformDirection (Vector3.forward * BulletSpeed);
 
 //note: I want the rotation of the actually fireing to have an 
 //angle of +20 degrees from which the bullet comes out of.

Any help is appreciated! thanks!

 }
 
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

1 Reply

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

Answer by maxkunes · Jan 03, 2014 at 04:26 AM

I see the way your doing it and I think that that is a unneeded approach to what you are trying to do. When ever I work with bullet spawns I would either use ray cast and there's a billion tutorial on that or the best option for what your doing is to make a bullet spawn object.

Create a empty game object Name it as Desired Position it linked to the tank's barrel as a child and rotate it to the desired degree Then fix the code...

 var firePos : Transform;
 
 function ShootCannon(){
  
 
  
 //this is the bullet creation
 var instance = Instantiate(Bullet, firePos.position, firePos.rotation);
 instance.velocity = transform.TransformDirection (Vector3.forward * BulletSpeed);
  
 //note: I want the rotation of the actually fireing to have an 
 //angle of +20 degrees from which the bullet comes out of.


In my opinion this is a very simple and effective way to solve your issue.

Warning Did not Test Code so there may be some simple errors but I dont think so...

Comment
Add comment · Show 4 · 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 Triqy · Jan 03, 2014 at 04:38 AM 0
Share

I would make it like that but the reason I didnt go that route is because the tank is being spawned reused over and over again after the player destory's it. I could create an empty and make it a child of the tank at the end of the muzzle but are all the clone object scripts unique to the clone itself??

avatar image Triqy · Jan 03, 2014 at 04:41 AM 0
Share

there is 4+ tanks of the same prefab(tank) in the scene.

avatar image Triqy · Jan 03, 2014 at 04:52 AM 0
Share

Never$$anonymous$$d lol you made me realize something. Im going to do it that way you said but ins$$anonymous$$d of having a separate script for the bullet spawner, im just going to use Transform.find(); and look up the transform and rotation of the bullet spawer form the tank AI Script. Thanks alot Playa!

avatar image Triqy · Jan 03, 2014 at 05:01 AM 0
Share

This is the revised code to anyone needing it...

 function ShootCannon(){
 
 var BulletSpawnPoint: Transform;
 BulletSpawnPoint = transform.Find("enemyTank/BulletSpawnPoint");
 
 var instance = Instantiate(Bullet,BulletSpawnPoint.transform.position,BulletSpawnPoint.transform.rotation);
 instance.velocity = BulletSpawnPoint.transform.TransformDirection (Vector3.forward * BulletSpeed);
 }
 

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

19 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

Related Questions

Instantiateon custom rotation doesn't work 2 Answers

Instantiate VS placement in editor 0 Answers

Instantiating objects at position 1 Answer

Dropping an object behind player in respect to rotation,How to drop an object behind the player 1 Answer

Objects Instantiating at wrong position 3 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