- Home /
Raycasting2D please help
im have problem you can help please? please i send my script i need convert Raycasting shoot at 2D can you help please
var hit : RaycastHit;
var fwd = Spawn.TransformDirection(Vector3.forward);
Debug.DrawRay(Spawn.position,fwd);
if(Physics.Raycast(Spawn.position,fwd,hit,range)){
if(hit.collider.tag == "Dirt"){
Instantiate(DirtImpact,hit.point,Quaternion.FromToRotation(Vector3.forward,hit.normal));
if(hit.rigidbody !=null)
hit.rigidbody.AddForceAtPosition(fwd * power,hit.point);
I don't understand the problem. Could you clarify what is wrong?
This script works for 3d fps I need to shoot a 2D view when you change the Vector2, right. a rigidbody to 2D does not work, but if you delete hit, it works but does not shoot ,Help
var hit : RaycastHit2D;
var fwd = Spawn.TransformDirection(Vector2.right);
Debug.DrawRay(Spawn.position,fwd);
if(Physics2D.Raycast(Spawn.position,fwd,hit,range)){
if(hit.collider.tag == "Dirt"){
Instantiate(DirtImpact,hit.point,Quaternion.FromToRotation(Vector3.forward,hit.normal));
if(hit.rigidbody2D !=null)
hit.rigidbody2D.AddForceAtPosition(fwd * power,hit.point);
Answer by Dave11 · Jun 27, 2014 at 06:02 AM
if(Canfire == true && IsReloading == false){
var hit : RaycastHit2D; hit = Physics2D.Raycast(transform.position,transform.right); var fwd = Spawn.TransformDirection(Vector2.right);
Debug.DrawRay(Spawn.position,fwd);
if(Physics2D.Raycast(Spawn.position,fwd,range)){
if(hit.collider.tag == "Dirt"){
Instantiate(DirtImpact,hit.point,Quaternion.FromToRotation(Vector3.forward,hit.normal));
if(hit.rigidbody !=null)
hit.rigidbody.AddForceAtPosition(fwd * power,hit.point);
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Help with Enemy AI 1 Answer
Accessing colliders, in if statement 2 Answers
Make Raycast that ignores certain tags? 0 Answers
how do i access an int var in a javascript and -= it from another javascript 1 Answer