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 JPRetro · May 16, 2013 at 08:16 PM · spritecolliderssidescroller

My player gameobject is ignoring colliders...

Hey people! I'm working on a 2D sidescrolling game, and a major problem I found with the player is that it completely ignores colliders. This is the first game I've scripted by myself and my code is reaaally janky, so be prepared... Any help would be extremely appreciated! Thanks guys :D

 //For changing tiles
 var left: Texture;
 var right: Texture;
 var front: Texture;
 var back: Texture;
 var idle: Texture;
 
 //For changing the movement
 var moveSpeed:float = 1;
 
 //Vars for changing the animation
 var uvAnimationTileX = 3; //Here you can place the number of columns of your sheet. 
                            //The above sheet has 24
 var uvAnimationTileY = 1; //Here you can place the number of rows of your sheet. 
                           //The above sheet has 1
 var framesPerSecond = 10.0;
 
 function Start () 
 {
         transform.position.y = 15;
 }
 
 function Update () 
 {    
 
     if (Input.GetKey(KeyCode.D)) 
     {
     
         renderer.material.mainTexture = right;
     
         //Changes character position and limits positions
         transform.position.x = transform.position.x + moveSpeed;
         
         // Calculate index
         var index: int = Time.time * framesPerSecond;
         // repeat when exhausting all frames
         index = index % (uvAnimationTileX * uvAnimationTileY);
  
         // Size of every tile
         var size = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY);
  
         // split into horizontal and vertical index
         var uIndex = index % uvAnimationTileX;
         var vIndex = index / uvAnimationTileX;
  
         // build offset
         // v coordinate is the bottom of the image in opengl so we need to invert.
         var offset = Vector2 (uIndex * size.x, 1.0 - size.y - vIndex * size.y);
  
         renderer.material.SetTextureOffset ("_MainTex", offset);
         renderer.material.SetTextureScale ("_MainTex", size);
     
     }        
     if (Input.GetKey(KeyCode.A))
     {
         
         renderer.material.mainTexture = left;
         
         transform.position.x = transform.position.x - moveSpeed;
         
         var indexA: int = Time.time * framesPerSecond;
         indexA = indexA % (uvAnimationTileX * uvAnimationTileY);
  
         var sizeA = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY);
  
         var uIndexA = indexA % uvAnimationTileX;
         var vIndexA = indexA / uvAnimationTileX;
  
         var offsetA = Vector2 (uIndexA * sizeA.x, 1.0 - sizeA.y - vIndexA * size.y);
  
         renderer.material.SetTextureOffset ("_MainTex", offsetA);
         renderer.material.SetTextureScale ("_MainTex", sizeA);
 
     }
     if (Input.GetKey(KeyCode.W))
     {
 
         renderer.material.mainTexture = back;
             
         transform.position.z = transform.position.z + moveSpeed;
         if (transform.position.z >= 22.0) {
         transform.position.z = transform.position.z - 1.0;
         }
         
 
         var indexW: int = Time.time * framesPerSecond;
         indexW = indexW % (uvAnimationTileX * uvAnimationTileY);
  
         var sizeW = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY);
  
         var uIndexW = indexW % uvAnimationTileX;
         var vIndexW = indexW / uvAnimationTileX;
  
         var offsetW = Vector2 (uIndexW * sizeW.x, 1.0 - sizeW.y - vIndexW * sizeW.y);
  
         renderer.material.SetTextureOffset ("_MainTex", offsetW);
         renderer.material.SetTextureScale ("_MainTex", sizeW);
         
     }
     if (Input.GetKey(KeyCode.S))
     {
         
         renderer.material.mainTexture = front;
         
         transform.position.z = transform.position.z - moveSpeed;
         if (transform.position.z <= -7.0) {
         transform.position.z = transform.position.z + 1.0;
         }
         
         var indexS: int = Time.time * framesPerSecond;
         indexS = indexS % (uvAnimationTileX * uvAnimationTileY);
  
         var sizeS = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY);
  
         var uIndexS = indexS % uvAnimationTileX;
         var vIndexS = indexS / uvAnimationTileX;
  
         var offsetS = Vector2 (uIndexS * sizeS.x, 1.0 - sizeS.y - vIndexS * sizeS.y);
  
         renderer.material.SetTextureOffset ("_MainTex", offsetS);
         renderer.material.SetTextureScale ("_MainTex", sizeS);
         
     }
 
 }
Comment
Add comment · Show 1
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 Fred_Vicentin · May 16, 2013 at 08:29 PM 0
Share

What Collider are you using ?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TheDarkVoid · May 16, 2013 at 08:33 PM

It's moving though colliders because your not using a CharacterController or a Rigidbody. I would recommend a CharacterController since it can be easily added to your current setup. Something like this, or if you want a more precise control and want to go through the extra steps you can do this.

Comment
Add comment · Show 1 · 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 JPRetro · May 17, 2013 at 07:41 PM 0
Share

Well I tried testing the more precise character control and it cant move, and just falls through the box colliders underneath it >_>

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

15 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Heath system need help 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Rigidbody/Physics Problem or Scripting problem? 1 Answer

Sprites and level tiles overlapping when they shouldn't 0 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