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 wicked208 · Apr 06, 2014 at 11:46 AM · rigidbodyvector3angleangles

problem with vector3.Angle with a fixed joint

i need measure angle of a rigidbody conected to a fixed joint, but inside the simulation the results are incorrect. i am using vector3.angle.

i need simulate a pendulum and measure the angle of the pendulum, any help? i include the project

project

this is the code:

 using UnityEngine;
 using System.Collections;
 
 public class angulo : MonoBehaviour {
 public Transform target;
 public float anguloMedida;
 public enum direccion{x,y,z}
 public direccion direccionActual = direccion.x;
 Vector3 valor;
 void Update() 
 {
 switch (direccionActual) 
 {
 case direccion.x:
 valor = transform.right;
 break;
 
 case direccion.y:
 valor = transform.up;
 break;
 case direccion.z:
 valor = transform.forward;
 break;
 }
 Vector3 targetDir = target.position - transform.position;
 Vector3 forward = transform.forward;
 float anguloMedida = Vector3.Angle(targetDir, valor);
 print (anguloMedida);    
 }
 }

alt text

new unity project - copia.zip (119.3 kB)
angle problem.png (102.5 kB)
Comment
Add comment · Show 1
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 Owen-Reynolds · Apr 06, 2014 at 04:58 PM 0
Share

Probably some of the points you measure from are wrong, or arrows are backwards... . Finding the pivot point from the Joint is a pain -- it's in local space coords (I think.) If you draw a picture and label things, the problem often becomes clear.

Then, the other most popular comment: we can't see your code, so can't know what's wrong.

2 Replies

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

Answer by Owen-Reynolds · Apr 07, 2014 at 10:34 PM

I don't understand those numbers, but maybe using transform.forward is the problem?

transform.forward is your personal forward, the blue arrow. It spins as the pivot spins, so they cancel. It's like driving a car in a circle while checking if the passenger is on your left or behind you.

Seems like there should be one fixed reference, such as comparing to up: Angle(Vector3.up, target.position - transform.position).

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 wicked208 · Apr 08, 2014 at 07:10 AM

Oh my god, its fixed now, you are right, i have to use vector3.up, i copy the code from the script reference they should change this, anyway thanks very much.

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

22 People are following this question.

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

Related Questions

Rigidbodies with fixed joint connection rotate instead of forward/back 1 Answer

Set rotation based on 1,1,1 style vector? How to convert vector3 to quaternion? 1 Answer

Angle between Ray and Normal 1 Answer

change angle of vector3 0 Answers

Rotate player (rigidbody) towards his movement 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