Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 PabloEscobarZ · Jul 22, 2015 at 02:07 PM · player movementcirclepivot-pointmathsmovedirection

left and right player movements restricted to a circle

i'm build a boss fight level where there is a cirlce platform this is what work: if i press up arrow the player go torwards the boss if i press down arrow the player go in the opposite site (as you can see in the image)

how can i move the player (left and right arrow ) with mathematical circle equation, to move the player around the boss??

Thanks in advance :)alt text

sas.jpg (90.8 kB)
Comment
Add comment · Show 5
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 PabloEscobarZ · Jul 22, 2015 at 12:46 PM 0
Share

here's the code

if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.UpArrow)) {

transform.LookAt(boss.transform.position);

player.transform.Translate(boss.transform.position.x, boss.transform.position.y, boss.transform.position.z);

}

avatar image PabloEscobarZ · Jul 22, 2015 at 12:50 PM 0
Share

i forget, the radius of circumference is 5

avatar image Hellium · Jul 22, 2015 at 12:52 PM 0
Share

That's a very strange way to move your player, but anyway ...

Try something with Transform.RotateAround

http://docs.unity3d.com/ScriptReference/Transform.RotateAround.html

and set the rotation back of your player.

avatar image PabloEscobarZ · Jul 22, 2015 at 01:00 PM 0
Share

maybe you're right hellium, but that's is how i think and i want to make for moving the player around,

this is my $$anonymous$$d pseudocode:

float XZradius // current position of player from the center of circumference

update() if (up or down arrow) float XZradius= player position x & player position z

if(left arrow //or right arrow//) go to left //or right arrow// while rotating around the boss with XZradius

you know what i mean...? i complicate my life -.-'

avatar image PabloEscobarZ · Jul 22, 2015 at 01:32 PM 0
Share

PORCO DIO

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · Jul 22, 2015 at 02:39 PM

I think you have the right idea, with XZradius. One trick to programming is to set up your personal variables that describe what you want. Change them based on how you're thinking of the problem. Then, "apply" them to the object.

Try:

 float playerAngle; // 0 to 360. Angle, from center, of player
 float playerRadius; // same as your XZradius

Left/right arrow keys add and subtract from the player angle. Very easy, it's just a number.

Then, don't use translate or rotateAround, or anything that moves the player form where it was. You know the angle from the center and the distance, so just put the player there. This is a little tricky,

 // how far the player is. This is straight North, which is 0 degrees:
 Vector3 toPlayer=Vector3.forward*XZradius;
 // now spin it to the correct angle:
 toPlayer = Quaternion.Euler(0,playerAngle,0)*toPlayer;

// now start it from the center: player.position=center+toPlayer;

Quaternion.Euler isn't as bad as it looks. It's just the way you "make" an angle. Multiply (angle times Vector3) is the way you spin a vector by an angle. But, if you've never worked with standard (non-Unity) vector math -- like Intro High School Geometry -- this will probably still be confusing.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to move Player Object horizontally with Touch while moving Forward Constantly? 1 Answer

Setting rotation of player equal to rotation of a Line from Line Renderer,Get the rotation of Line Renderer and equal it to the rotation of the player 0 Answers

player flipping in the air when colliding with a wall shorter than him.,how do i stop my player from flipping 0 Answers

Put objects in (front) and direction on a sphere 0 Answers

Why is this script not moving my character and constantly getting this error given below,why is this script not moving my character 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