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
1
Question by Persona · Mar 20, 2011 at 07:41 PM · collisionmovementrigidbodytriggerrotatearound

Rigidbody Version of RotateAround

I'm making a game and the current script uses transform.RotateAround to move in a circle around another game object. The down side of this is that the game object moving will go through other Trigger colliders, making it useless against another set coding I have. I need some way to manipulate the rigid body by converting Transform.RotateAround.

Coding:

    var degree: float = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
    transform.RotateAround (Target.position, Vector3.up, -degree);
    //Moves towards the target or away depending on up or down key
    var translate: float = Input.GetAxis ("Vertical") * speed * Time.deltaTime;
    rigidbody.AddForce(0, 0, translate * 50);

Trigger Script:

function OnTriggerEnter(other: Collider){
if(other.gameObject.CompareTag("Wall")){
rigidbody.velocity = -rigidbody.velocity;
    }
}
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
3
Best Answer

Answer by Statement · Mar 30, 2011 at 02:15 AM

For the trigger: You don't need triggers to bounce stuff off though. Just use a regular collider without any renderer. You can set layermasks so it only affect the ball if you want. Finally you could apply a bouncy physics material to it so it bounces right off.

For the controls: I toyed around a bit with this. See if this is somewhat like you expect.

I created a webplayer so you can try the controls in action.

var speed = 10.0f; var target : Transform;

function FixedUpdate () {

 var horizontal = Input.GetAxis("Horizontal");
 var vertical = Input.GetAxis("Vertical");

 var direction = (target.position - rigidbody.position).normalized;
 var rotation = Quaternion.AngleAxis(horizontal * 60, Vector3.up) * direction * Mathf.Abs(horizontal);
 var desired = rotation + vertical * direction;
 var change = desired * speed - rigidbody.velocity;

 // Debug lines: Red - current heading
 //              Blue - applied heading
 Debug.DrawLine(rigidbody.position, rigidbody.position + rigidbody.velocity, Color.red);
 Debug.DrawLine(rigidbody.position, rigidbody.position + change, Color.blue);

 rigidbody.AddForce(change * Time.deltaTime, ForceMode.VelocityChange);

}

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 efge · Mar 20, 2011 at 07:46 PM

You could use Rigidbody.AddTorque or Rigidbody.AddRelativeTorque.


Edit:

var torque : float = Input.GetAxis("Horizontal");
rigidbody.AddRelativeTorque (0, torque, 0);

(And remember: Put all physics related stuff in the function FixedUpdate.)

Comment
Add comment · Show 4 · 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 Persona · Mar 20, 2011 at 07:51 PM 0
Share

I don't know how to convert the data from the Transform.RotateAround to AddTorque.

avatar image efge · Mar 20, 2011 at 08:45 PM 0
Share

Edited my answer. (You could also multiply torque and speed.)

avatar image Persona · Mar 20, 2011 at 09:33 PM 0
Share

It can't move left or right at all now though.

avatar image Persona · Mar 24, 2011 at 04:39 AM 0
Share

I still can't get it to work

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

No one has followed this question yet.

Related Questions

Make characters go through each other 1 Answer

RigidBody - GameObject moves but mesh stays! 1 Answer

move camera when it collides with a trigger 1 Answer

The trigger enter detect fast moving object more accurate 2 Answers

Trigger between 2 kinematic bodies not firing? -1 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