Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 sami1592 · Apr 02, 2014 at 04:25 PM · collisionrigidbodyfixedjoint

Fixed Joint - Collision Problem

Scenario: its like a temple run game, it has player(still), a platform(it moves) and obstacle(which will be created after a certain time until the game ends)

in my 3D game currently I have a
1. moving rigidbody - platform(has velocity, platform like cube)
2. another rigidbody - obstacle(no velocity, a cube)
3. player - rigidbody (a cube)

At a time i have 2 platforms in the scene, they are destroyed and created to make a infinte platformer style game.

Obstacle are generated via script. the steps are -
1. create a obstacle
2. add a fixedJoint component to the obstacle
3. set the connectedBody property of the fixedJoint to platform in the OnCollsionStay() function

so far, everything is working as expected.

problem occurs when the player collides with the obstacle, the collision happens abnormally. Like there was a explosion occurred and the player just shoots off from there. And if the player hits the top of the obstacle this abnormality is more clear.

I like to say that when i drag and drop the obstacle in the scene view, add joint, set connected body by hand instead of script the collision(between player and obstacle) is normal. but infinite obstacle cannot be generated by hand, I found out when i was testing these things.

I am putting the adding joint code and Creating obstacle code here.
First the create obstacle code ---

 #pragma strict
 
 var obstacleSpawnPoint: GameObject;            // the position where the obstacle will be created
 var obstacleHolderVariable: GameObject;        // obstacle prefab
 
 
 function Start () {
     InvokeRepeating("CreateObstacle", 1, 3);
     //CreateObstacle();
 } 
 function CreateObstacle()
 {
     //yield WaitForSeconds(5);
     Instantiate( obstacleHolderVariable, obstacleSpawnPoint.transform.position, obstacleSpawnPoint.transform.rotation );
 }

Now the Joint adding code ---

 #pragma strict
 
 var isObstacleCreated:boolean ;
 
 function Start () {
     Destroy(gameObject, 15);
     isObstacleCreated = false;        // so that only one obstacle is created at a point at a time
 }
 function OnCollisionStay(collisionInfo : Collision) {
     
     if(isObstacleCreated == false)
     {
         Debug.Log("entered - COLLISION___STAY ");
         var fixedJointVariable :FixedJoint =gameObject.AddComponent(FixedJoint);
         //var fixedJointVariable :FixedJoint =gameObject.GetComponent(FixedJoint);
         //var rigidbodyOfPlatform :Rigidbody = GameObject.Find("platformWhole_v2").rigidbody;
 
         // getting the rigidbody of that platform 
         var rigidbodyOfPlatform :Rigidbody = collisionInfo.gameObject.rigidbody;    
         if(rigidbodyOfPlatform == null || fixedJointVariable == null)
         {
             Debug.Log("rigidbody NOT found!");
         }
         else
         {
             // setting the connected body of fixedJoint(obstacle) to the platform rigidbody
             fixedJointVariable.connectedBody = rigidbodyOfPlatform;        
         }
         isObstacleCreated = true;
     }
 }


The thing that bugging me most is i don't even know how to figure out the problem, any suggestion will be appreciated

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 koray1396 · Apr 02, 2014 at 04:42 PM 0
Share

I think you have a problem of anchor and connected anchor points. The joint might have been trying to connect to somewhere else.

avatar image sami1592 · Apr 02, 2014 at 04:57 PM 0
Share

can you please explain it a little better? i don't really know about anchor and how it effects other things :) This abnormal problem is driving me crazy! :( :(

avatar image sami1592 · Apr 02, 2014 at 05:08 PM 0
Share

Hey! there is no anchor point in Fixed Joint, anchors are in Hinge Joint.

avatar image koray1396 · Apr 02, 2014 at 05:36 PM 0
Share

Fixedjoint also has anchor and connectedanchor values, even if not in the editor.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by koray1396 · Apr 02, 2014 at 05:13 PM

https://docs.unity3d.com/Documentation/ScriptReference/FixedJoint.html

try setting anchor and connectedAnchor setting of fixedJoint with

 fixedJointVariable.anchor = Vector3 (...); // refers to the the local position in respect to the player.
 fixedJointVariable.connectedAnchor = Vector3(...); // refers to the local position relative to the obstacle.


If the above does not help, please try moving connectedBody line 27 and the above, just after creating the fixed joint. the problem might also be that, when you create a joint and do not attach it to a rigidbody, it attaches itself to world coordinates. Therefore, you might be first attaching your fixed joint to (0,0) right after you create the fixedjoint, causing the player to explode.

also a suggestion; why do you create the joint over and over? Just create one, when collision is detected, change connectedBody and enable, when collision is finished, disable and remove connectedbody. this might be more practical and fix your problem as well.

Comment
Add comment · Show 1 · 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 sami1592 · Apr 03, 2014 at 12:36 PM 0
Share

Scenario: its like a temple run game, it has player(still), a platform(it moves) and obstacle(which will be created after a certain time until the game ends) 1. so i have to create obstacles repeatedly and add joint component, and then set its connected body. 2. I have set its anchor to Vector(0, 0, 0). It still does not work :( 3. Joint.autoConfigureConnectedAnchor is set to True. so it is set automatically. Should i change it? 4. I have change code line 27 as you suggested

     function OnCollisionStay(collisionInfo : Collision) {    
         if(isObstacleCreated == false )
         {
             var rigidbodyOfPlatform :Rigidbody = collisionInfo.gameObject.rigidbody;
             var fixedJointVariable :FixedJoint =gameObject.AddComponent(FixedJoint);
             fixedJointVariable.anchor = Vector3(0, 0, 0);
             fixedJointVariable.connectedBody = rigidbodyOfPlatform;    
         
             isObstacleCreated = true;
         }
     }

  1. what can i do figure out what the error is :( :(

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

21 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

Related Questions

How do I connect two objects together in the scene? 1 Answer

How to speed up? 3 Answers

Having trouble turning a Transform movement into a Rigidbody force. Code included 1 Answer

Rigidbody Collision? 1 Answer

RigidBody Clings to Walls 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