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
2
Question by wano · Sep 02, 2012 at 06:11 PM · gameobjectpositioning

moving an object along a surface, then rotating it around end of surface

Im trying to move a circular gameobject along a surface and then rotate it around the corner / end point of that surface.

I think it can be soloved using trigonometry, but not 100 percent sure. I can move the object along the surface using this calculation...offset = tan(A) x radius of circle. this gives me a distance I can offset the circle by, but having trouble with the rotation.

please see attached image for a better understanding of what i am trying to achieve. alt text

It would be really helful if anyone can give me any advice on how to to resolve this problem. thanks in advance.

javascript code for stage1 of the diagram....

 var player : GameObject;
 var d1 : float = 1;
 var offset : float = 0;
 
 function Update () {
     var angleA : float = Vector3.Angle(player.transform.position - transform.position, transform.forward);
     var angleB : float = 90 - angleA;
     var angleC : float = angleA + angleB;
 
     var angleCRadians : float = angleC * (Mathf.PI/180);
     var angleCTan = Mathf.Tan(angleCRadians);
     offset =  angleCTan x d1;
 
     transform.position += transform.TransformDirection(Vector3( -offset, 0, -d1));
 }


offset problem-unity-page-001.jpg (220.1 kB)
Comment
Add comment · Show 2
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 @rppe · Sep 02, 2012 at 07:13 PM 0
Share

Ok, so it when the center of your circle reaches the end of the wall, it wants to rotate around that corner. the distance it will move is 1/4 of the circumference I think, so here is what I would do. Use the Rotate around function here http://docs.unity3d.com/Documentation/ScriptReference/Transform.RotateAround.html just rotate around that corner for however long you want, just remember its 1/4 of the circumference.

avatar image wano · Sep 02, 2012 at 07:25 PM 0
Share

thanks for the reply @rppe, the problem i have is rotating the circle so that the entire circle is just behind the corner when the player is looking at the corner.

Im trying to build an enemy cover system so that an enemy can go to a coverzone (the circle) and be behind the corner. He can then lean out from that cover and shoot at the player.

thanks.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by @rppe · Sep 02, 2012 at 08:10 PM

So your formula only offsets him in one direction? Just use that until the difference between his X position and the edge of the wall is his radius, and then use the same formula to calculate his z offset on the Right side of the wall. that should give you the effect you want,

David

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 @rppe · Sep 02, 2012 at 08:12 PM 0
Share

the player wouldnt notice anyway, hes hiding from the player :p

avatar image wano · Sep 02, 2012 at 08:55 PM 0
Share

thanks $$anonymous$$.

you are right. the formula above only effects the coverzone in one direction. I do have more code that makes the coverzone (circle) go down the left hand side of the wall if the player is above the wall, but only posted half the code so i could put across a clearer question (if that makes sense ;)

my idear is I will have a coverzone on all the corners of buildings etc in my game and they will move left or right of that coner depending on where the player is. they will turn off when the next coverzone / corner is in view. I can then have an array of all active coverzones that my enemy transforms can go to / hide behind.

you are also right with your solution, I did try that at some point. But when I have a corner that isnt a 90 degree corner it starts to not work so well (for example a corner or tip of a starfish type shape). I thought I could rotate it round the corner and it may solve the issue. another example would be if the wall just has a slight kink in it, then the circle ends up inside the wall when changing the offset direction. Hope you get what i mean, i dont think i have explained that very well.

$$anonymous$$aybe its starting to get to complex. I might have to think about a more simple meathod :)

or maybe someone has a better solution for an enemycover system, cant seem to find any meathods when googling etc.

thanks.

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

8 People are following this question.

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

Related Questions

Trouble with positioning 2 Answers

Fixing instantiated object in one direction? 0 Answers

GameObject positioning in World Space 2 Answers

View an array of the transform position/rotation of all game objects with a specified tag., 0 Answers

Wrong positioning of game objects after instantiating them 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