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 Dunny · Feb 13, 2013 at 05:25 PM · movementaxispivotpivot-point

Devil May Cry style Lock-on Movement?

alt text

Hi,

I'm wondering if anyone can assist me with a problem I am having.

Basically I have my player pivot around an object with a Static Camera.

I need to adjust my controls depending upon the position of my player in relation to the Object.

If this isn't clear enough I will try to explain further.

Many Thanks

unityhelp.gif (16.3 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 Dunny · Feb 14, 2013 at 12:46 PM

I should point out the Character is fixed, I just want a rotation for the Player much like a lock-on in Devil May Cry or a Boxing Game.

Thanks

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 robertbu · Feb 14, 2013 at 12:44 PM

If the structure is a clean as you make it here, you can figure out the angle of player with respect to pivot/object using Mathf.Atan2(). Something like (untested);

 Vector3 v3Pos = player.transform.position - pivot.transform.position.
 float angle = Mathf.Atan2(v3Pos.y, v3Pos.x);
 if (angle < 0.0f) angle += 360.0f;

With the angle, you can code your behaviors however you want based on the quadrants you specified above.

Comment
Add comment · Show 5 · 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 robertbu · Feb 14, 2013 at 01:12 PM 0
Share

I'm confused about the problem you are trying to solve. I've not played "Devil $$anonymous$$y Cry," and watching a trailer video on YouTube did not help. I'm guessing at what you want. Any game object will have a transform.forward, transform.up, and a transform.right. The left, down, and back will be the negative of these values. If your joystick uses these vectors for movement, then the joystick will always move the character with respect to his space (i.e. up with the joystick will always move the character forward no matter which way he is facing). You can also use local coordinates for these movements and accomplish the same thing.

As for locking on, take a look at Transform.LookAt() or Quaternion.SetLookRotation().

If I've missed what you are asking, pointing to a specific video at a specific time would be helpful.

avatar image Dunny · Feb 14, 2013 at 03:30 PM 0
Share

Thanks for the help.

Basically I'm still stuck and have decided to just calculate the angle my character has rotated around the object but this is giving me an angle of 0-180 on each side of the Character as apposed to a 360 degree value.

Can anyone shed any light on this problem?

$$anonymous$$any Thanks

avatar image robertbu · Feb 14, 2013 at 03:58 PM 0
Share

Atan2() as I've outlined above will give a signed angle. I believe it returns -180 to 180 which is why I added the "angle + 360.0" above. This is not relative to the character, but as a clock rotation. If you are looking straight down, you will want to use x,z rather than the x,y I used above.

avatar image robertbu · Feb 14, 2013 at 04:16 PM 0
Share

Here is a text script. Drag your Pivot game object on to goPivot then hit the 'A' key to report the angle. This is looking down, so the Atan2 call use 'Z' rather than 'Y'.

 public class PivotAngle : $$anonymous$$onoBehaviour {
     
     public GameObject goPivot;
     
     void Update () {
         
         if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.A)) {
             Vector3 v3T = transform.position - goPivot.transform.position;
             float angle = $$anonymous$$athf.Atan2 (v3T.z, v3T.x) * $$anonymous$$athf.Rad2Deg;
             Debug.Log ("Angle = "+angle);
         }
     }
 }

Angle are counter clockwise (right hand rotation).

avatar image Dunny · Feb 14, 2013 at 05:01 PM 0
Share

$$anonymous$$any thanks for all the help, I ended up going with,

angle = transform.eulerAngles.y;

that seemed to do the trick.

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

9 People are following this question.

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

Related Questions

Rotating Cuboid Around Pivot 2 Answers

A node in a childnode? 1 Answer

Authoritative Networking 2D Movement 0 Answers

Why does the player keep pointing in a specific direction after moving? 0 Answers

Constrain axis of isometric camera ("vertical" only) 0 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