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 voncarp · Jan 17, 2012 at 05:45 AM · rotationprojectile

Rotation Projectile Script Difficulties

Hi

I created a cylinder game object to sample as an arrow. When I run the script the projectile instantiates vertically (which seems to be a common problem for some), instead of firing straight.

This script is attached straight on my character (which currently is just a capsule) and is called by pressing a touchscreen firebutton. The arrow prefab currently has no other scripts attached to it. I've also attempted to adjust the prefab in the proper direction to no avail.

My efforts are in the following code:

 var projectile : Rigidbody;
 var speed = 20;
 var fireitem : GameObject;
 var target : Transform;
 var ammoCount = 20;
 var reloadTime = 0.5;
 
 private var lastShot = -10.0;
 
 function fire () {
     if (Time.time > reloadTime + lastShot && ammoCount > 0) {
 
         var misslelocation = fireitem.transform.position;
         var misslerotation = transform.rotation;
 
     //    var misslerotation = Quaternion.FromToRotation(Vector3.up, -transform.forward);    
     //    var misslerotation = Quaternion.Euler(90, 0, 0);
        //    var launchbullet : Rigidbody = Instantiate (projectile, misslelocation,  gameObject.transform.rotation );
        //    var launchbullet : Rigidbody = Instantiate (projectile, misslelocation,  transform.rotation );
 
         var launchbullet : Rigidbody = Instantiate (projectile, misslelocation, misslerotation);
 
         launchbullet.transform.LookAt(target);
            launchbullet.rigidbody.AddForce ( launchbullet.transform.forward * speed);
       
         Physics.IgnoreCollision( launchbullet. collider, transform.root.collider );    
         lastShot = Time.time;
            ammoCount--;
        }
 
 }    

In the code, I've left in some different approaches that I've tried from other users issues with projectile rotation within this site.

Could anyone assist me or point me in the right direction of why my projectile will not fire properly?

Thanks

Comment
Add comment · Show 4
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 syclamoth · Jan 17, 2012 at 07:24 AM 0
Share

Are you sure it's actually wrong? Does the shaft of the arrow point along the arrow's z axis?

avatar image voncarp · Jan 17, 2012 at 07:38 AM 0
Share

No it doesnt, but it does as a prefab. I've tried to adjust it through Quaternion.Euler and a FromToRotation approach. Each try, it still shoots in the vertical position. Is there another area that you know of that I should check?

Thanks.

Also, I am using the Standard Assets $$anonymous$$obile - Player Relative Setup (3rd Person) with Unity Android, if any of this makes a difference. In the Unity editor and android application that I've pushed it to, the response is the same.

avatar image syclamoth · Jan 17, 2012 at 08:02 AM 0
Share

Where is 'target' relative to the spawn position? I can't see anything obviously wrong with the script, so I'm really just throwing troubleshooting questions at you to see if there's something odd about your setup...

avatar image voncarp · Jan 17, 2012 at 09:49 AM 0
Share

The target is an empty game object that moves around based on a raycast from the my camera that shoots towards the center of the screen. In the code above, the empty target game object would be the variable "target". The spawn position is on the character controller named "fireitem", also in the above code.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DBar · Aug 19, 2014 at 07:50 AM

When theory fails, you have TRIAL & ERROR, try this before launching and pause, i dont understand where is the LAUNCH origin so this is rough but it works on my ship:

      var ShootDirection = launchbullet.transform.forward; // To try the SHOOT DIRECTION
      
     Debug.DrawRay (misslelocation.transform.position,   misslelocation.transform.worldToLocalMatrix.MultiplyVector(ShootDirection) * 30, Color.green);
 Debug.Break();
     
         




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

6 People are following this question.

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

Related Questions

How can I rotate a rigid body based on its velocity? 3 Answers

Shoot projectile according to rotation 2 Answers

Rotation troubles 2 Answers

How do I rotate this plane to face the position of the mouse? 1 Answer

Instantiated object using parent's transform as world axes 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