- Home /
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);
}
}
}
Comment
Answer by Justin Warner · Apr 14, 2011 at 10:08 PM
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(_________);
}
}
}
Your answer
Follow this Question
Related Questions
Unrealistic Fps Shooting? 1 Answer
Raycasr in my fps? 1 Answer
How can i make a raycast in my fps game? 1 Answer
Which is better, shooting a bullet from camera or from the gun itself? 3 Answers
Simulating gravity to Raycast bullet 3 Answers