x


Simple Rigidbody / force question

This seems to be something that would be used in a lot of games, but I can't find an answer to this.

What I want to do:

My player will contanstantly be hit by spheres, as she is hit with a sphere I wish to add force relative to the direction the sphere was heading and depending on where the player was hit.

For example if the player was hit on the left side by a sphere heading in the X direction, I would want the player to fly off in the x direction, with some z direction because she wasn't hit in the center, she was hit on the side. If she was hit in the center she would head directly in the x direction.

I cant seem to add a picture, heres a link. I hope it helps. http://imageshack.us/photo/my-images/444/forceq.jpg/

The only solutions i've encountered is to add a physic material to the player, such as Bouncy, and give the spheres great mass. However I cannot do this in my game because it is networked.

Thanks in advance!

more ▼

asked Nov 05 '11 at 12:01 AM

vivalarosa gravatar image

vivalarosa
106 10 10 12

Is your player a rigidbody or a CharacterController?

Nov 05 '11 at 12:33 AM aldonaletto

Rigidbody

Nov 05 '11 at 05:42 AM vivalarosa
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

Does anyone know how to do this? As mentioned it would seem like a pretty common thing. Another example would be a player being hit by a car, you'd want the player to be pushed in the direction the car hit you and if you were hit on the side, you'd fly off to the side a bit.

more ▼

answered Nov 14 '11 at 12:21 AM

vivalarosa gravatar image

vivalarosa
106 10 10 12

(comments are locked)
10|3000 characters needed characters left

The simplest way would be to use Rigidbody.AddExplosionForce when you detect the collision, otherwise you can use Rigidbody.AddForce.

more ▼

answered Nov 05 '11 at 06:34 AM

kevork gravatar image

kevork
415 1 2 4

(comments are locked)
10|3000 characters needed characters left

Thanks, i know how to add the forces but i need to add the forces depending on where the player was hit. I presume it has something to do with adding collision from the collision point in the same velocity that the object was heading - an offset accounting for where in the rigidbody it was hit.

more ▼

answered Nov 05 '11 at 09:47 AM

vivalarosa gravatar image

vivalarosa
106 10 10 12

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1875
x1793
x292

asked: Nov 05 '11 at 12:01 AM

Seen: 917 times

Last Updated: Nov 14 '11 at 12:21 AM