Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MC HALO · May 01, 2011 at 04:19 AM · raycast

Why is my raycast not working?

Hey guys, i was wondering if someone could help me, basically the problem is that i was creating a ray cast in my update i created one and it was working perfectly. but after i created the second ray cast underneath the first one the second one does not even work but the first still works. Basically what happens is i have said to the ray if the first ray hits the tag name wall turn Boolean "WalkingRight = true" it works fine. oh and yes when the ray hits the wall in the tag it prints a message "you hit right wall" that tells me the rifts tag is working and then if i try the something with the other ray it give out no message and does not set the left boolean to true at all. the 1st ray only seems to work. can you please have a look at my script and tell me what is wrong. the ray is in the update function thank you very much in advance :) MCHALO

private var xOffset = 0.0;

var Water : float = 4;

//public var lockedRotation: float = 0;

var speed : float = 5;

var jump : float = 10;

var DoubleJump : int = 1;

var JumpReset : int = 2;

var JumpResetWallHit : int = 1;

var JumpVariance : float = 5;

//ar CenMass : float = 1;

var HitWallCollider: boolean = false;

var RayCastDist : float = 3;

var LeftRayDist : float = 3;

//var springSpeed : float = 10;

var ClimbSpeed : float = 5;

static var Climbing: boolean = false;

var WalkingRight : boolean = false; var WalkingLeft: boolean = false;

//var SecWait : float = 0.3;

function Awake (){

//rigidbody.constraints = RigidbodyConstraints.FreezePositionZ| RigidbodyConstraints.FreezeRotationZ //|RigidbodyConstraints.FreezeRotationY| RigidbodyConstraints.FreezeRotationX;

}

function Update () {

var Hit : RaycastHit; var Hit2 : RaycastHit;

Debug.DrawRay(transform.position , Vector3.right * RayCastDist, Color.green);

 //var fwd = transform.TransformDirection (Vector3.right);

 if (Physics.Raycast (transform.position, Vector3.right,Hit, RayCastDist))
  {

    if(Hit.collider.gameObject.tag == "Wall"){
        print ("Right side hit");
               WalkingLeft = false;
                   WalkingRight = true;

} } Debug.DrawRay(transform.position , Vector3.left* LeftRayDist, Color.green);

// var fwd = transform.TransformDirection (Vector3.right);

 if (Physics.Raycast (transform.position, Vector3.left,Hit2,  LeftRayDist)) 
 {

     if(Hit2.collider.gameObject.tag == "Wall2"){
        print ("Left Side hit ");

         WalkingLeft = true;
         WalkingLeft = true;

} }

}

function Start () {

//rigidbody.isKinematic = true;

} function FixedUpdate () { //var movement : float = Input.GetAxisRaw("Horizontal") speed; //movement = Time.deltaTime;

 //rigidbody.centerOfMass = Vector3 (0, CenMass, 0);

 if(WalkingRight == false){
 if(Input.GetKey("d"))

 {

     rigidbody.velocity = Vector3(speed , rigidbody.velocity.y, 0);
 }
 }

 if(WalkingLeft == false){
 if(Input.GetKey("a")){

     rigidbody.velocity = Vector3(-speed , rigidbody.velocity.y, 0) ;
 }
 if(WalkingLeft == true  || WalkingRight == true){

 rigidbody.freezeRotation = true;


 }
 }




 if (DoubleJump > 0)
 {           
     if (Input.GetKeyDown(KeyCode.Space))
     {
             rigidbody.isKinematic = false;
             rigidbody.velocity = Vector3(0,jump ,0);


             DoubleJump -= 1;
     }
 }
 if (Input.GetKey(KeyCode.Space))
 {
         rigidbody.isKinematic=false;
         rigidbody.AddForce(Vector2(0,JumpVariance));
         Climbing = false;

         //constantForce.relativeForce = Vector3(0, -10, 0);
 }
 if (Climbing == false)
 {
     rigidbody.isKinematic = false;

     //transform.Translate(Vector3(movement,0,0)); // you need to change this line dude it is making the code 
     // play up. because you have movement defined up above this part would not let my booleans work and the is really making 
     // the jump play about. So see if you can find another line of code for this :) 
 }
 if (Climbing == true)
 {
     //transform.localPosition.x = 0;
     transform.rotation = transform.parent.rotation;
     transform.parent.gameObject.rigidbody.AddRelativeForce(Vector3.right * Input.GetAxis("Horizontal") * 3, ForceMode.VelocityChange);
 }   
 if(Input.GetButtonDown("Jump")&& (HitWallCollider == true )){


     Debug.Log("Gravity is true player will fall");

  rigidbody.useGravity = true;
  Debug.Log("Drag is set back to 0");

             rigidbody.drag = 0;
             Debug.Log("Kinematic is set to false move free");
             rigidbody.isKinematic = false;

                 Debug.Log("Hey! you hit the wall DoubleJump is reset");

             Debug.Log("Not hitting wall");
 HitWallCollider = false;

} }

function OnCollisionStay ( other : Collision) { if (other.gameObject.tag == "Ground") { if(!Input.GetAxis("Horizontal")) { rigidbody.velocity.x = 0;

     }
 }

}

function OnCollisionEnter ( hit : Collision) { if (hit.gameObject.tag == "Ground") { //if(other.transform.position.y<transform.position.y)

     DoubleJump = JumpReset;

 }


if (hit.gameObject.tag == "Wall" ){

Debug.Log("Hitting the wall"); rigidbody.isKinematic = true; Debug.Log("can not move Kin = ture"); //rigidbody.useGravity = false; Debug.Log("drag is set hold player still "); rigidbody.drag = 13;
Debug.Log("You hit the wall"); DoubleJump = JumpResetWallHit; //rigidbody.AddForce(0, 0, 0); HitWallCollider = true; //rigidbody.constraints = RigidbodyConstraints.FreezePositionZ| RigidbodyConstraints.FreezeRotationZ //|RigidbodyConstraints.FreezeRotationY| RigidbodyConstraints.FreezeRotationX; Debug.Log("Waiting 5 sec before you drop"); yield WaitForSeconds(1);
Debug.Log("Gravity is true you will fall"); WalkingRight = false; rigidbody.useGravity = true; Debug.Log(":)"); rigidbody.drag = 0;

 }


 if (hit.transform.tag == "Ground"){

 HitWallCollider = false;
 rigidbody.isKinematic = false;
 //rigidbody.useGravity = true;
 rigidbody.drag = 0;   

 }

 }










function OnTriggerStay ( other : Collider) { if (other.gameObject.tag == "ladder") { if (Input.GetKey("w")) { transform.Translate ( Vector2(0, ClimbSpeed Time.deltaTime)); rigidbody.isKinematic = true; DoubleJump = JumpReset; Climbing = true; } if (Input.GetKey("s")) { transform.Translate (Vector2(0, -ClimbSpeed Time.deltaTime)); rigidbody.isKinematic = true; DoubleJump = JumpReset; Climbing = true; }

     if (transform.parent.tag == "ladder")
     {
         transform.localPosition.x = 0;
         //transform.rotation = transform.parent.rotation;
         //transform.parent.gameObject.rigidbody.AddRelativeForce(Vector3.right * Input.GetAxis("Horizontal") * 10, ForceMode.VelocityChange);
     }
 }
 if (other.gameObject.tag=="water")
 {
     DoubleJump=JumpReset;
     rigidbody.velocity.y/=Water;
 }

}

function OnTriggerEnter ( other : Collider) { if (other.gameObject.tag=="water") { jump*=Water; } }

function OnTriggerExit ( other : Collider) {

 if (other.gameObject.tag == "ladder")
 {
     rigidbody.isKinematic = false;
     transform.rotation = Quaternion.identity;
     Climbing = false;
     transform.parent = null;

 }
 if (other.gameObject.tag=="water")
 {
     jump/=Water;
 }

} function SetXOffest(offset: float){ xOffset = offset; }

//function WallCast (){ // var hit : RaycastHit;

 //  Debug.DrawRay (transform.position, Vector3.right * RayCastDist, Color.green); 

//if(Physics.Raycast(transform.position, Vector3.right, RayCastDist, 10)){ //Debug.DrawRay (transform.position, Vector3.right * RayCastDist, Color.red); //if(hit.collider.gameObject.tag == "Wall"){ //Debug.Log("Hey You hit the wall congratz");

//} //} //}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Joshua · May 01, 2011 at 04:48 AM

You are using Vector3.left which does not exist. You only have up/right/forward. Replace Vector3.left with -Vector3.right.

Also, try to not capitalize the first letters of variables - right now you're switching in between capitalizing and not-capitalizing which is confusing. Same goes for indentation.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MC HALO · May 01, 2011 at 05:50 AM 0
Share

still not working :( yea sorry about the vector3.left i just noticed that lol

avatar image MC HALO · May 01, 2011 at 06:09 AM 0
Share

are you sure left don't work because it is working for me know

avatar image MC HALO · May 01, 2011 at 06:10 AM 0
Share

oh yea when i write vector3. it asy Up, right, forward, back, and left no joke lol

avatar image MC HALO · May 01, 2011 at 06:16 AM 0
Share

thanks anyway's at lest you helped me.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to Raycast from Camera View Point? 2 Answers

Third Person Shooting Script Stopped Working 1 Answer

[RESOLVED]Raycast problem 2 Answers

Raycast2D Only returns true 1 Answer

Game Object flies out of screen when dragged 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges