x


raycast not doing good

Right now when i hit something with my raycast, it just tells me what it is... what i want the raycast to do is if it hits a rigidbody, make that rigidbody fly off as if it were hit by a bullet. thanks!

  function Update()
  {

    if(Input.GetMouseButton(0))

    {
      var forward = transform.TransformDirection(Vector3.forward);
      var hitInfo : RaycastHit;
      if (Physics.Raycast (transform.position, forward, hitInfo, 1000)) {
        print(hitInfo.collider);
      }
    }
  }
more ▼

asked Apr 14 '11 at 10:02 PM

niceperson87 gravatar image

niceperson87
12 7 8 8

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

1 answer: sort voted first

http://unity3d.com/support/documentation/ScriptReference/Rigidbody.AddForce.html

Yea... Just get the rigid body, and do .AddForce ().

  function Update()
  {

    if(Input.GetMouseButton(0))

    {
      var forward = transform.TransformDirection(Vector3.forward);
      var hitInfo : RaycastHit;
      if (Physics.Raycast (transform.position, forward, hitInfo, 1000)) {
        hitInfo.rigidbody.AddForce(_________);
      }
    }
  }
more ▼

answered Apr 14 '11 at 10:08 PM

Justin Warner gravatar image

Justin Warner
6.3k 19 27 65

thanks for the help!@

Apr 15 '11 at 12:08 AM niceperson87
(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:

x2994
x1528
x1172
x308
x129

asked: Apr 14 '11 at 10:02 PM

Seen: 884 times

Last Updated: Apr 14 '11 at 10:06 PM