• 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 henmachuca · Sep 02, 2020 at 02:38 PM · projectileeuleranglesaiminglookrotation

Align rotation to a vector3 point

Hi, I'm trying to allign my "spawn projectile point" to where my mouse cursor is, but I'm having a bit of a problem. As you can see in the image, it has a slight offset.

alt text

I've set my player right hand IK to 1 already and I'm setting it to aim towards that silver sphere (that is my cursor position)

     private void OnAnimatorIK()
     {
         // Weapon aim at target IK
         animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 1f);
         animator.SetIKPosition(AvatarIKGoal.RightHand, aimTarget.position);
     }

The thing is that as you can see in the picture, the z-axis of my spawn point is a bit off. I have the code in the player to fire the bullet and pass the bulletSpawnPoint (that is a transform I have parented to the player bones to indicate where I want the bullet to spawn from) as an Euler Angle:

 private void Fire()
         {
             var go = Instantiate(bulletPrefab);
             go.transform.position = bulletSpawnPoint.position;
             var bullet = go.GetComponent<Bullet>();
             bullet.Fire(go.transform.position, bulletSpawnPoint.eulerAngles + aimTargetOffset, gameObject.layer);
         }

And lastly I have a script in the bullet that tells it to move forward based on the parameters I've set

     public void Fire(Vector3 position, Vector3 euler, int layer)
     {
         transform.position = position;
         transform.eulerAngles = euler;
         transform.position = new Vector3(transform.position.x, transform.position.y, 0f);
         transform.rotation = Quaternion.LookRotation(transform.forward, Vector3.forward);
     }
 
     void Update()
     {
         transform.Translate(Vector3.forward * velocity * Time.deltaTime);
     }  

Does anyone have any ideas?

Thank you

aim-offset.jpg (18.1 kB)
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

Answer by whogas · Sep 02, 2020 at 03:32 PM

Not entirely sure about your rig setup here, but is it just that the right hand is pointing correctly, but that doesn't translate to the gun tip as you expect?

alt text


cxsmqy44ta.png (81.4 kB)
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 whogas · Sep 02, 2020 at 05:18 PM 0
Share

Based on your follow-up:

"The IK is aiming correctly since the joint is aiming at the sphere. The thing is though, that I would like the projectile that comes out ot the bulletSpawnPoint to be facing the sphere as well, because as you can see it will miss it by a little bit."

I understand what you're asking now. You should just be able to offset the aiming point by the hand-coordinate system's delta-Y to the height of the gun. So the hand is pointing at a location delta-Y down from the click point (in the hand's coordinate system).

Should be able to look at the coordinate systems for the hand, gun, and click point to figure this out.

avatar image henmachuca whogas · Sep 02, 2020 at 06:33 PM 0
Share

Thanks for the reply. Any practical example that can help me out?

avatar image
0

Answer by henmachuca · Sep 02, 2020 at 05:06 PM

The IK is aiming correctly since the joint is aiming at the sphere. The thing is though, that I would like the projectile that comes out ot the bulletSpawnPoint to be facing the sphere as well, because as you can see it will miss it by a little bit.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

135 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 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 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 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 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 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 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

Enemy AI prediction aiming isn't working as expected 1 Answer

Look Rotation flipping object rotation after 180 degrees 1 Answer

Turret rotation on one axis problems 2 Answers

Aiming in code only. 1 Answer

making the weapon shoot whatever the crosshair is on 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges