Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

Search the Community

Showing results for tags 'raycast'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


    • Introduce yourself
    • Discussions
    • Showcase
    • Need help?
    • Seeking team members?
    • Offtopic
    • unity3D | Example Projects
    • unity3D | Scripts
    • unity3D | Shaders
    • unity3D | Tutorials
    • 3D models
    • Animated 3D Models
    • Graphic design
    • Textures
    • Sounds
    • Other
    • FPSKit Download
    • FPSKit Modifications/Tutorials
    • FPSKit WIP/Showcase
    • Discussions / Bug reports
    • Sell
    • Request
  • Photon's Tutorials
  • Busy People's Introductions
  • Mars' Modular Multiplayer Photon FPS Kit's Topics
  • Mars' Modular Multiplayer Photon FPS Kit's Reviews
  • Photon's Photon General
  • Photon's Showcase
  • Mars' Modular Multiplayer Photon FPS Kit's Updates


  • Free Projects
  • Free Assets
  • Game Demos
  • Photon's Files


  • Community Calendar

Facebook URL

Twitter URL

IndieGoGo URL

Kickstarter URL


GreenLight URL



Found 12 results

  1. Hi Does anyone know how could i limit or clamp raycasting to a certain radius, currently the raycast could go behind my character, how would i go solving about it ?
  2. Use raycast as a pointer ?

    I'm using third person camera for a car. this car have a gun. it shooting but because the camera is above the car it get hard the aim at any enemy or spot far from the car. I need from my raycast give me the coordination (X,Y) of any object block the ray, so that can i use it for my bullet direction. here is my code: using UnityEngine; using System.Collections; public class carCam : MonoBehaviour { Camera car_cam; public Transform target; void Start() { car_cam = GetComponent<Camera>(); } void Update() { Vector3 camScreen = new Vector3(0.5f, 0.5f, 0f); // center of the screen float rayLength = 500f; RaycastHit hit; Ray ray = car_cam.ViewportPointToRay(camScreen); Debug.DrawRay(ray.origin, ray.direction * rayLength, Color.red); if (Physics.Raycast(ray, out hit, rayLength)) { print ("Looking at : " + hit.transform.name); } } } What ever in the middle of my screen my bullet can reach it. I don't know if this is right or wrong but i have to try.
  3. Basic Raycast Gun C#

    Here are two scripts that i recently made, they are really basic so the gun can´t reload and it does have not a mag, but anyway, i wanted to share them to the forum Shooting.cs using UnityEngine; using System.Collections; public class Shooting : MonoBehaviour { private RaycastHit hit; AudioSource audiosource; public AudioClip shoot; void Awake () { audiosource = GetComponent<AudioSource>(); } void Update () { if (Input.GetMouseButtonDown (0)) { bang(); audiosource.PlayOneShot(shoot, 0.7f); } } void bang() { Vector3 myTransform = transform.transform.forward; Physics.Raycast (transform.position, myTransform, out hit, 50); if ((Physics.Raycast (transform.position, myTransform, out hit, 50)) && (hit.collider.gameObject.tag == ("enemy"))) { hit.collider.SendMessageUpwards("DoDamage"); print ("hit"); } } } EnemyHealth.cs using UnityEngine; using System.Collections; public class EnemyHealth : MonoBehaviour { public float EnemyHealthVar = 100; void Update () { if (EnemyHealthVar <= 0) { Debug.Log("ded"); Destroy(gameObject); } } public void DoDamage() { EnemyHealthVar -= 50; } } As im a begginer, please tell me if there is any error or anything that can be improved
  4. Raycast doesn't detect tag

    Hello guys! i'm making a very little shotscript for my game, and i'm having some trouble... I don't know if it's a raycast problem or a tag problem. this is my code: using UnityEngine; using System.Collections; public class Shoot : MonoBehaviour { public GunScript gunData; //for later use void Update () { RaycastHit hit; Vector3 fwd = transform.TransformDirection(Vector3.forward); //a little shortcut if(Input.GetButton("Fire1")&& Physics.Raycast(transform.position, fwd, 1000)){ // the distance of the raycast is temporal, suggestions are always welcome! Debug.Log("We have shot" + transform.tag); Debug.DrawRay(transform.position, fwd, Color.red); //IMPORTANT: the ray draws jist a little bit, will add an image below /*if(hit.transform.tag == "Concrete"){ //for later use //disabled by now, will enter something here when the problem is solved } */ } } } As you can see, it doesn't detect the tag, it says "Untagged" :c
  5. camera going thru

    The plan is two make this available on PC only. Use keyboard to control the helicopter, use mouse to orbit view about helicopter. Problem: The camera is going thru the terrain, it will probably also go thru all meshes Video here shows current nasty... http://youtu.be/SeV_P2RaMoo Here is the scene showing the assets connected to the camera... https://www.dropbox.com/s/s3my1v54oem2gsx/terrainthru.PNG Here is the code .. check the attempts I have made (very badly) .... using UnityEngine; using System.Collections; public class CamMouseOrbit : MonoBehaviour { public Transform target; public float distance = 10.0f; public float xSpeed = 5f; public float ySpeed = 2.5f; public float distSpeed = 10.0f; public float yMinLimit = -20.0f; public float yMaxLimit = 80.0f; public float distMinLimit = 5.0f; public float distMaxLimit = 50.0f; public float orbitDamping = 4.0f; public float distDamping = 4.0f; private float x = 0.0f; private float y = 0.0f; private float dist; void Start () { dist = distance; Vector3 angles = transform.eulerAngles; x = angles.y; y = angles.x; // Make the rigid body not change rotation if (rigidbody) rigidbody.freezeRotation = true; } void LateUpdate () { if (!target) return; Vector3 oPos = transform.position; x += Input.GetAxis ("Mouse X") * xSpeed; y -= Input.GetAxis ("Mouse Y") * ySpeed; distance -= Input.GetAxis ("Mouse ScrollWheel") * distSpeed; y = ClampAngle (y, yMinLimit, yMaxLimit); distance = Mathf.Clamp (distance, distMinLimit, distMaxLimit); dist = Mathf.Lerp (dist, distance, distDamping * Time.deltaTime); transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.Euler (y, x, 0), Time.deltaTime * orbitDamping); transform.position = transform.rotation * new Vector3 (0.0f, 0.0f, -dist) + target.position; // Vector3 newPos = transform.rotation * new Vector3 (0.0f, 0.0f, -dist) + target.position; // newPos.y = Mathf.Clamp(newPos.y,Terrain.activeTerrain.SampleHeight(oPos),0.5f); // transform.position = newPos; // float dist1 = newPos.y - Terrain.activeTerrain.SampleHeight(newPos); // // if(dist1 < 0.5) // { // newPos.y = newPos.y + 0.7f; // } // transform.position = newPos; // Vector3 wantedPosition = transform.rotation * new Vector3 (0.0f, 0.0f, -dist) + target.position; // // //Vector3 bumperRayOffset; // Vector3 back = target.transform.TransformDirection(-1 * Vector3.forward); // RaycastHit hit; // // //if (Physics.Raycast(target.TransformPoint(bumperRayOffset), back, out hit, 2.5f) // if (Physics.Raycast(target.position, back, out hit, 2.5f) // && hit.transform != target) // ignore ray-casts that hit the user. DR // { // // clamp wanted position to hit position // wantedPosition.x = hit.point.x; // wantedPosition.z = hit.point.z; // wantedPosition.y = Mathf.Lerp(hit.point.y + 1.0f, wantedPosition.y, Time.deltaTime * 5.0f); // } // // transform.position = Vector3.Lerp(transform.position, wantedPosition, Time.deltaTime * 5.0f); } float ClampAngle (float a, float min, float max) { while (max < min) max += 360.0f; while (a > max) a -= 360.0f; while (a < min) a += 360.0f; if (a > max) { if (a - (max + min) * 0.5f < 180.0f) return max; else return min; } else return a; } } Please help ... : ( We will braai together when all this comes thru .. : )
  6. Pickup script

    Hi everyone, does someone know or have a script where if you look at a object it gets highlighted (change color, get a border or something). thanks
  7. Pyshics.AreaCast?

    Hi everyone! I'm triying to make a minio AI like any moba I have the minion follow an array of waypoints and i desire that this minion can see anything inside our area (and i want this for turrets too) I try sphereCast because i think this will make a sphere over the minion, but the minion only can see the object front of he I search on google about this but i don't found anything similiar for this I ask, Exist a function that make an area that can detect if any object is inside?
  8. Blood Splat

    Hey! I found this package quite a while ago and I thought it would be nice of me to share it with you guys! Of course this requires some/lots of power from your computer but it's a starter and if you're smart enough you might optimize it and make it how you desire. Example Pic: LINK: http://forum.unity3d.com/threads/2562-blood-splatter Direct Download Link to Package: http://forum.unity3d.com/attachment.php?attachmentid=587&d=1155964730 You could also achieve the effect when getting shot/shooting others so blood splats. I experimented a bit and got the results. Enjoy...
  9. Help with a scripting :(

    Hello community my first official post on something i need help with...i am working on a basic hunting fps.... i was hoping i can get some help on a raycast tutorial on making an object run away or disappear when the main character gets to close....possibly a youtube link would be nice or tryied and true code that one of you guys made that works....thanks
  10. Hi All... A while back aldonetto from answers.unity3d helped me get a teleport script working. I have modified to have Audio - Particle FX (Though particle FX Wont Disable) Here is the script, Below it i will post info on the actual issue So.. When the raycast hits and teleports me there... I don't want it to be instant.. I want it to take a little time.. like.. 1.5 So my particle FX can have enough time to play and still look - function beautifully. I'm not sure how to use timers or pretty much anything to do with vectors - transform.. So this has been pretty much impossible for me to do myself. So I'm here "Best Unity Community" Asking For Your Help! Information is greatly appreciated, Thank you for the time you took to read this post .
  11. Raycast doesnt really work.

    Im having trouble with raycast, it doesnt uses the right position as you can see in the pic below, i checked all rotations and position but evreything is right: The script im using:
  12. Raycast Debug,

    Debug.DrawLine is not working, Getting this error BCE0051: Operator '*' cannot be used with a left hand side of type 'UnityEngine.Ray' and a right hand side of type 'float'. Code: function Update() { if(Input.GetKeyDown("v") && CanAttack == true) { //Arm.animation.Play("Knife"); audio.PlayOneShot(SwingSound); var Hit : RaycastHit; var cam : Transform = Camera.main.transform; var DirectionRay = new Ray(cam.position, cam.forward); Debug.DrawLine(cam, DirectionRay * Range, Color.blue); if(Physics.Raycast(DirectionRay, Hit, Range)) { if(Hit.transform.tag == "Untagged") { audio.PlayOneShot(HitSound); //var enemy = Hit.collider.gameObject.GetComponent(); //enemy.ApplyDamage(damage); } } print("You swing your sword"); Wait(); } }