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 LSPressWorks · Apr 12, 2015 at 08:28 PM · mousefollow

misaligned mouse follow, with VIDEO

So here's a video of what's happening to it. It occurs from even small bumps sometimes. http://youtu.be/EJlbAMo4NHU So I have a script to make an onboard turret follow the mouse. Code Block A:

 public function setaim()
 {
 
         aimingArm.transform.localPosition = Vector3(0,0,0);
         ray = camcam.ScreenPointToRay(Input.mousePosition);
         p = ray.GetPoint(32);//was 132
         dir1 = (this.transform.position.x - p.x);
         dir2 = (this.transform.position.y - p.y);
         angle = Mathf.Atan2(dir1, dir2) * Mathf.Rad2Deg;
         aimingArm.transform.LookAt(aimPoint.transform.localPosition);
         aimingArm.transform.eulerAngles = Vector3(0,0,angle * -1);
             
         
 }

black ball = character. Purple ball = mouse cursor. So what happens is that the gun(aimingarm) will start to look at the yellow line. That's the dark blue gun, where it starts. When I pull the trigger, it momentarily bounces to where it's supposed to be looking, green line, aqua gun. Then bounces back. This is not predictable except that it happens a little more following collisions. I checked that the camera isn't tilted, and that the gun isn't tilted. The overall effect is that while it shoots where it's supposed to go 90% of the time, there is that 10% and the epileptic cannon.

setaim() is called for mouse follow regularly, as well as the moment before the gun fires. aimingarm attaches via configurable joint on pickup, which sets position, anchors and constraints in it's onCollision call. It kind of seem like Input.mousePosition doesn't provide proper numbers until a click occurs. What's going on how do I fix it?

Thanks guys and gals! gun twitch

Comment
Add comment · Show 3
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 _Gkxd · Apr 15, 2015 at 12:24 AM 0
Share

When you say regularly, do you mean inside Update()?

This probably won't fix your problem, but having both LookAt() and setting eulerAngles might be redundant. As far as I know, LookAt() is just a convenient way of rotating the positive z-axis to point towards something (it does the math for you). Setting eulerAngles right after would overwrite any changes that LookAt does, since it also sets the orientation of the transform.

avatar image LSPressWorks · Apr 15, 2015 at 01:11 AM 0
Share

First off, thank you very much. regularily = inside fixedUpdate() and each time when the trigger is pressed, before shots are launched and recoil is applied. I removed the Eulers, and it brought me back to the original issue. When it's just lookAt(p), the gun is locked facing down and it sling my character about wildly(which is in my redacted comments if I actually read them...That's actually explained well enough by what you just told me. Since Eulers set the orientation. I've been reading and working on this, and this is where I am at....

 public function setaim()
 {
             
             ray = camcam.ScreenPointToRay(Input.mousePosition);
                             //cam behind, use + cam for position, - caused revered y co ordiantes
             p = ray.GetPoint( ai$$anonymous$$gArm.transform.position.z + camcam.transform.localPosition.z);//was 32 flat
              dir1 = (ai$$anonymous$$gArm.transform.position.x - p.x)*-1;//x reveresed when set to localEulers
              dir2 = (ai$$anonymous$$gArm.transform.position.y - p.y);
              angle = $$anonymous$$athf.Atan2(dir1, dir2) * $$anonymous$$athf.Rad2Deg;
             //ai$$anonymous$$gArm.transform.LookAt(p);//behaves incorrectly.
             ai$$anonymous$$gArm.transform.localEulerAngles = Vector3(0,0,angle);
             
 }


switching to localPosition and localAngels has reduced the size of the error, adn it slowly works it's way back in after the mouse is moved alot and the gun fires...

by printing the output of the angels, it appears that the gun is tilting backward, despite having projection set, and again in the eulers...

I am so at a loss.

avatar image _Gkxd · Apr 15, 2015 at 02:26 PM 0
Share

You might want to do this inside of Update() or LateUpdate(), which are executed every frame. I don't think FixedUpdate() gets executed every frame.

0 Replies

· Add your reply
  • Sort: 

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

gameobject follow mouse with on mouseclick instantiate 0 Answers

how to make a charecter controller 1 Answer

Stop object rotation 1 Answer

Mouse follow performance in iPhone 1 Answer

Getting a weapon to follow the mouse cursor( 3D) 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