Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 shahinexir · Sep 23, 2012 at 02:53 PM · collisiongameobjectoncollisionenterdetectioncolider

WALL collision detection problem... help!!!!

hi . i have a 2d game and i have a player with a script attached to him as u can see bellow.on the other hand i have some game objects as walls .

im using capsul colider with is trigger off and rigid body with use gravity on him but no is kinematic,on my player . and its better to mention that ive set all kinds of collision detection from district to continiuous dynamic on my player but nothing changed . right now its set to district . and also ive freezed my player on x and z position and also rotation .

and on my wall game object we have no script ... and im just using a box colider with no is trigger .

now the problem is that when i jump on the wall , player can walk on top of that and every things ok . but if i colide with wall from left or right or down side , i mean for example if i go straight through a wall left or right side , player passes through the wall !!!!

i just want to stop passing through walls and be able to recognize them az an real wall and colide with them ! so i really need your help .

this is my player entire script , i just put the whole script available for u for better understanding but dont pay attention to some of those comments , cuz their not related to this part ! :

var playerSpeed : int;

var playerRunSpeed : int;

var jumpHeight : float;

var extraJumpHeight : float;

var fireBallPrefab : Rigidbody;

var playing : boolean;

static var score = 0;

static var coins = 0;

static var lives = 3;

function Start ()

{

    spawn();
    playing = true;

}

function Update ()

{

if (playing)

{

//1- player movement

 amtToMove = playerSpeed * Input.GetAxis("Horizontal") * Time.deltaTime;     // amount to move the player 
   
 transform.Translate(Vector3.right * amtToMove, Space.World);   
     

//------------------------------------------------------------------------

//2- player rotation...!

  if (Input.GetKey("left") || Input.GetKey("a"))
  {  
    transform.rotation = Quaternion.Euler(0,180,0);
        
  }      
  if (Input.GetKey("right") || Input.GetKey("d"))
  {
  
    transform.rotation = Quaternion.Euler(0,0,0);    
        
  }



//------------------------------------------------------------------------------------------------------------------------

 //3- player jump
 // player can countinusly jump when you hold the up button. if its transform position in y axis is (on the ground) 
 //here should add extra jump code later
 
 // extra jump ?X?
 

if ( (Input.GetKey("up") || Input.GetKey("w") )&& Mathf.Abs(rigidbody.velocity.y) <0.01 )

   {
     audio.Play();
     rigidbody.velocity.y = 4.5;
     
     amtToJump = jumpHeight + Time.smoothDeltaTime ;
     transform.Translate(Vector3.up * amtToJump );
     

   }

 

//--------------------------------------------------------------------------------------------------------------

 //4- instantiate fireBall
    
 if (Input.GetKeyDown("space"))
 {
    var tempfireBall : Rigidbody;
    tempfireBall = Instantiate(fireBallPrefab,Vector3(transform.position.x , transform.position.y, transform.position.z),transform.rotation);
 }   
    

}

}

//--------------------------------------------------------------------------------------------------------------

 //5- onGUI function/scoring part...

function OnGUI()

{

GUI.Label(Rect(10,10,120,20), "Score: " +playerScript.score);

GUI.Label(Rect(10,30,120,20), "coins: " +playerScript.coins);

GUI.Label(Rect(10,50,120,20), "lives: " +playerScript.lives);

}

//--------------------------------------------------------------------------------------------------------------

 //6- player collisions
 
 

function OnCollisionEnter(other : Collision)

{

 // ?X? ===> here we want to check direction of the collision ...?!

//if(other.gameObject.tag == "leftBody" || other.gameObject.tag == "rightBody")

if(other.gameObject.tag == "enemy" )

 { 

 playing = false;
 playerScript.lives -= 1;
   
 amtToJump = jumpHeight + Time.smoothDeltaTime ;
 transform.Translate(Vector3.up * amtToJump );
 transform.position.z = -1;
 
 yield WaitForSeconds(3);
 
   
    if (playerScript.lives == 2)
    {
    Application.LoadLevel(1);
    }
    
    
    if (playerScript.lives == 1)
    {
    Application.LoadLevel(2);
    }
 
    if (playerScript.lives == 0)
    {
    Application.LoadLevel(3);
    playerScript.score = 0;
    playerScript.coins = 0;
    playerScript.lives = 3;

    }
 
    
    
 
 }  
 
 
 

if(other.gameObject.tag == "deathZone") {

 playing = false;
 playerScript.lives -= 1;
     
 
     if (playerScript.lives == 2)
    {
    Application.LoadLevel(1);
    }
    
    
    if (playerScript.lives == 1)
    {
    Application.LoadLevel(2);
    }
 
    if (playerScript.lives == 0)
    {
    Application.LoadLevel(3);
    playerScript.score = 0;
    playerScript.coins = 0;
    playerScript.lives = 3;

    }
       
 }  
 
 

if(other.gameObject.tag == "flag") {

  var playerTransform = GameObject.Find("flag").transform;
   
  playerTransform.parent = transform;
     
 }
  
    
        

if(other.gameObject.tag == "door")

 { 

   playing = false;

   gameObject.renderer.enabled = false;
   
   yield WaitForSeconds(1.5);
   
   Application.LoadLevel(4);

    playerScript.score = 0;
    playerScript.coins = 0;
    playerScript.lives = 3;

 }      
    
      
        

if(other.gameObject.tag == "teleportGate1")

 {   
        
   if (Input.GetKey("down") || Input.GetKey("s")) 

    {

       print("xxx2");
       transform.position.z = 0.8;

    } 
    
 }
 
        

if(other.gameObject.tag == "teleportGate2")

 {  

   Application.LoadLevel(5);

 }
 
 

if(other.gameObject.tag == "doorToLevel1")

 {   

   playing = false;
   gameObject.renderer.enabled = false;
   
   yield WaitForSeconds(1.5);
   Application.LoadLevel(0);    
 
 }
 

}

//--------------------------------------------------------------------------------------------------------------

  //7- player spawn function...

function spawn()

{

transform.position = GameObject.FindGameObjectWithTag("spawnPoint").transform.position;

}

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

0 Replies

· Add your reply
  • Sort: 

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Detect collision from a another object,Detect collision from another script 2 Answers

KnockBack Effect. 1 Answer

collision detection 4 Answers

How do i destroy only 1 object when 2 instances of the same object collide ? 2 Answers

Collision Detection for a Prefab? 3 Answers


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