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 Pengu · Jul 15, 2010 at 02:10 AM · rigidbodyinstantiateforceragdolladding

adding force to instantiated ragdoll

Hello Unity-Community,

I've managed to create a ragdoll via ragdoll-wizard and it works so far. Now I'm trying to add force to the instantiated ragdoll because the enemy is shot but it only collapses on the spot.

Here is my script which is attached to the enemy:


var deadReplacement : Transform;

function Update() { if(HitCollisionScript.NPC_dead) { replaceWithRagdoll(); } }

function replaceWithRagdoll() { // Destroy ourselves Destroy(gameObject);

 // Replace ourselves with the dead body
 if (deadReplacement) 
 {
     var deadBody = Instantiate(deadReplacement, transform.position, transform.rotation);
     deadBody.rigidbody.AddForce(transform.forward * 1000);
 }

}


I would really appreciate a hint why it is not working

greetings Pengu

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

4 Replies

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

Answer by spinaljack · Jul 15, 2010 at 12:15 PM

You've set the instantiate pointer to a transform i.e. a set of coordinates and scales.

What you need to do is set the instantiate pointer to a GameObject prefab.

var deadReplacement : GameObject;

Then you drag your ragdoll into an empty prefab to save it.

Then you drag the prefab onto the deadReplacment slot in the inspector.

Make sure that the root object of the ragdoll prefab has a rigid body as you're trying to access it.

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
2

Answer by The-Arc-Games · Nov 04, 2011 at 07:30 AM

I'm sorry to reply just now but we made a tool for the asset store that shows how to do this even in the awesome and feature full free version (forum thread and links here), that I'd suggest you install to get a number of leads on how to properly ragdoll and interact with game models and physics.

Besides, you basically need to 'intercept' the collider or trigger event, and add a relative force in the point of contact, like this

 rigidbody.AddForceAtPosition(myforce,myimpactpoint, myforcemode);

which basically adds a force to the rigidbody into a point, causing torque and translation. Note in fact that the forcemode is very important, since it determines the kind of impulse that the rigidbody will receive.

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 SpaceManDan · Apr 14, 2016 at 11:37 PM 0
Share

Im also having issues with this. I have a ragdoll that has all it's rigidbodies set to is$$anonymous$$inematic. On collision enter I turn all the rigidbodies to is$$anonymous$$inematic==false. But the impact force is lost during the computation causing the ragdoll just to drop to the ground limply.

You are suggesting that I (if I am to understand this correctly.) store the impact point that triggers the event and calculate force on my own and reapply a new force that simulates the impact using

rigidbody.AddForceAtPosition(myforce,myimpactpoint, myforcemode);

That may just work. Good idea.

avatar image
0

Answer by Pengu · Jul 15, 2010 at 08:45 PM

weird, setting the instantiate pointer to a GameObject prefab didn't make any difference for me but

Make sure that the root object of the ragdoll prefab has a rigid body as you're trying to access it.

ringed the bells!

my mistake was that I didn't access the ragdoll root bone directly (or which ever part I wanted to push)


instead of

FAIL:

deadBody.rigidbody.AddForce(transform.forward * 1000);

I did

OK:

gameObject.Find("ragdoll_pelvis").rigidbody.AddForce(-transform.forward * 1000)


"ragdoll_pelvis" = name of my root object / -transform = to push him backwards

and it worked!

thanks for the help spinaljack :)

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 Dedou · Feb 02, 2011 at 02:07 PM 0
Share

Hi, I used your technique, and it work great, so thanks for that. But I get a weird clipping bug. When the camera go pass the position where the Ragdoll was created and where I destroy the original character, the Ragdoll get clipped and disapear from screen. If I move back a bit, the Ragdoll reappear. Any Idea what could cause this? Thanks

avatar image Dedou · Feb 02, 2011 at 02:23 PM 0
Share

Ok, I found the solution. The Update when offscreen in the $$anonymous$$esh Renderer was not set to true. I set it, and it work now.

avatar image
0

Answer by OoglyWoogly · Apr 18, 2011 at 06:02 PM

You should use AddRelativeForce so that the ragdoll moves relative to the direction it has been hit from. The syntax is the same as add force. Its just that if it is shot from the left it will fall to the right, rather than always falling in one direction.

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

2 People are following this question.

avatar image avatar image

Related Questions

Ragdolling not properly problem. 1 Answer

Applying force to a rigidbody 2 Answers

Disabling Kinematic on hit 2 Answers

Projectile not moving properly in top down 2d shooter 2 Answers

How to calculate force from explosion on a rigidbody 1 Answer


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