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 djfatsteve2 · Mar 22, 2014 at 05:21 AM · rotationmobilequaternion

Projectile Rotation To Match Direction Shot? Mobile Joystick

I've scanned over tons of threads, even looked into most of the Quaternion documents to try to solve my problem myself.. So no flaming me for not trying! ;)

Anywho.. I've got this neat little 2d rpg I'm developing for Android/iOS, in which I use two joysticks to interact with the character. The left joystick moves the current character around while the right shoots a projectile in whichever direction the joystick is pointed.

So far I've got everything working except the dang rotation of the projectile.
I've got it shooting in the right direction, I just can't seem to make it rotate to point in the direction it was shot.

I've tried the Quaternion.LookRotation(shootDir)... however there is a problem with this method and the way my game is set up. I need the X rotation of the projectile to REMAIN -90.

Any alternatives/thoughts? :) Would save me a headache or two. Either way, I'm going to figure it out.

All of this code is on one page: playerweapon.js

Mobile vector grab for direction and majorStrike(); function call when touching.

 #if UNITY_ANDROID
     if(Input.touchCount >= 1){
         for(var touch1 : Touch in Input.touches) { 
             if(touch1.position.x > Screen.width/2 && touch1.position.y < Screen.height/3*2){
             innerJoy2.transform.position = camera.main.ScreenToViewportPoint(touch1.position)+Vector3(0,0,0.1);
             var shootDir = new Vector3(outerJoy2.transform.position.x - innerJoy2.transform.position.x, 0,outerJoy2.transform.position.y - innerJoy2.transform.position.y);
             shootDir.Normalize();
             majorStrike(shootDir);
             }
         }
     }else{
         touching = false;
     }
 #endif







majorStrike function as follows

 function majorStrike(shootDir : Vector3){
     atkcounter += Time.deltaTime;
     if(attackingnow == false){
         attackingnow = true;
         animScript.strike();
         strike(shootDir);
         }
     if(atkcounter >= playerStats.fireSpeed){
         attackingnow = false;
         atkcounter = 0.0;
         }
 }






And now the strike() function which is called within majorStrike()

 function strike (shootDir : Vector3) {
 
 //ASSASSIN WEAPONS! :D//
 if(PlayerPrefs.GetFloat("weapon") == 1){
 randAngle = Random.Range(-10,10);
 var daggerPrefab1 = Instantiate(dagger1, Vector3(transform.position.x,-5,transform.position.z), Quaternion.Euler(-90,180,0));
 daggerPrefab1.rigidbody.velocity = shootDir*-daggerSpeed1;
 }





I will buy whoever saves me from racking my brain even more tonight a steak dinner and a beer.

Thanks, Steven

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 djfatsteve2 · Mar 22, 2014 at 08:27 PM

To anyone else having this problem... I've solved the issue of the rotation of my projectile on the x axis. It NEEDED TO REMAIN -90 degrees to keep the sprite facing the camera and not sideways. I achieved this after instantiating by rotating the localEulerAngles on the projectile ;)

Code below for fix. I added the += 180 to the y axis because my projectiles images were backwards yet moving in the correct direction.

 //ASSASSIN WEAPONS! :D//
 if(PlayerPrefs.GetFloat("weapon") == 1){
 curWeapon = sword;
 useDir();
 transform.position.y = -transform.position.z/10000+0.5;
 randAngle = Random.Range(-10,10);
 var daggerPrefab1 = Instantiate(dagger1, Vector3(transform.position.x,-5,transform.position.z), Quaternion.LookRotation(shootDir));
 daggerPrefab1.rigidbody.velocity = shootDir*-daggerSpeed1;
 daggerPrefab1.transform.localEulerAngles.x = -90;
 daggerPrefab1.transform.localEulerAngles.y += 180;
 }



Learning on our own does pay off eventually. Never hurts to ask though ;)

The game continues! :D

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 sarthakshah · Aug 19, 2014 at 07:18 AM

Hi, I have done similar thing , but using touch. I have tried to rotate bow using touch and asper its angle, i have called fire function, in which projectile is instantiated, and then force os given to it, and after that it will rotate in real time.

See below post, i have posted my answer, it may help you.

http://answers.unity3d.com/questions/656781/unity3dprojectilearrow-of-bow-is-not-rotating-as-p.html

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

20 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 avatar image

Related Questions

why is my character rotation always 180° after joystick is released. 1 Answer

Problem finding relative rotation from one quaternion to another 4 Answers

How can I get the rotation between two objects 1 Answer

Rotate object following mouse movement. Object jumps/ flips 1 Answer

How to make a plane face a static but rotating camera? 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