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 nash · Nov 11, 2011 at 03:03 PM · c#charactercontroller

characterController rotate around an object help!

Is there a way to rotate an Object around a targetObject using the characterController.move(Vector3) function rather than the transform.rotation/transform.rotate function?

Comment
Add comment · Show 4
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 syclamoth · Nov 11, 2011 at 03:18 PM 0
Share

Why are you so desperate to use a 'move' function to do rotation? Doesn't that seem a little strange to you?

avatar image nash · Nov 11, 2011 at 08:24 PM 0
Share

because I made a finished script on zoom pan dolly that I attached to a camera when the camera hits other game objects it does'nt pass through it because of the characterController that I attached to It, I used characterController to move the camera on its, zoom pan dolly functionality the only thing lacks right now is the orbit function that is the only thing right now that I'm looking for to orbit the camera around a target object using characterController.move() because this avoid the camera to pass through objects and see through it

avatar image nash · Nov 11, 2011 at 08:25 PM 0
Share

I hope someone has an Idea how to do this, thanks

avatar image nash · Nov 11, 2011 at 08:30 PM 0
Share

I also tried to move it using transform.rotation and transform.rotate(), but the camera looses it's collision on other objects it see's through objects, I have tried to attached rigid body and collider to it but it fails, because when it hits other game objects it goes crazy, goes wild rotating rapidly unexpectedly and sometimes bounces

that's why I'm crazy knowing about how to orbit a an object to a target object using the characterController.move()

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by aldonaletto · Nov 12, 2011 at 01:12 AM

You can make the character follow a perfect circle around the target, but if there's some obstacle the character may get stuck. A better approach is trying to move in a circle, but allowing eventual trajectory changes due to obstacles - this can modify the circle radius sometimes.
The idea is to calculate a curPos vector from the target to the character, then save in newPos this vector rotated by an angle proportional to Time.deltaTime: newPos - curPos is the distance the character must move in this frame. If some object is hit, the character may move closer to or farther from the target, and this new distance will be kept until another obstacle is hit.
I included gravity effects in the script below; just comment this line out if you don't want gravity.

public Transform target; public float speed = 30f; // speed in degrees per second public float gravity = 10f; // gravity, if you want to use it

CharacterController character;

// call this function in LateUpdate void RotateChar(){ // make sure the variable "character" contains the controller: if (!character) character = GetComponent(CharacterController); // curPos = vector from target to character: Vector3 curPos = transform.position - target.position; // rotate curPos by the appropriate angle and save in newPos: Vector3 newPos = Quaternion.Euler(0, speed Time.deltaTime, 0) curPos; // calculate the displacement to move Vector3 displacement = newPos - curPos; // if you don't need gravity, comment out this line: displacement -= gravity Vector3.up Time.deltaTime * Time.deltaTime; character.Move(displacement); // move by the distance calculated transform.LookAt(target); // keep looking to the target }

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 nash · Nov 12, 2011 at 09:20 PM 0
Share

thanks for the Idea :) this is what I'm looking for

avatar image Yohann1172 · Nov 06, 2015 at 04:32 PM 0
Share

@aldonaletto thank you for this (it works nicely) but how could i get to it to honor a fixed distance from the target? (i.e. keep the circle radius from changing, even if that means the character gets stuck)

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

CharacterController in instance object 1 Answer

First Person Controller MouseLook on Android 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Stopping the Character Controller 0 Answers

C# FP_Camera not following Character Controller 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