- Home /
Raycasr in my fps?
Okay so right now i have this code
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);
}
}
}
But that just tells me what im hitting at.. how can i make it so if it hits something with a rigidbody, it will fly of as if it were a bullet? thankss
exact duplicate (52638) : http://answers.unity3d.com/questions/52638/raycast-not-doing-good
Answer by Justin Warner · Apr 14, 2011 at 10:11 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(_________);
}
}
}
Don't double post please! And also format your code next time please.
Thanks, also, use the 10101 button to make it look pretty like above... Just highlight, then push the button.
Good luck!
Your answer
Follow this Question
Related Questions
raycast spawn problem 0 Answers
raycast not doing good 1 Answer
How to get bullets to hit crosshair 2 Answers
How do i make a Railgun style effect with a raycast shot? 1 Answer
shooting multiple enemies using raycast 2 Answers