Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by MDennis · Jul 20, 2011 at 01:34 PM · physicsrigidbodycollideriphoneaccelerometer

Physics collider behaving very odd on iphone

The Problem:

Picture yourself hold the iphone landscape, so that the home button is facing downwards. At either side of the iphone screen are walls (so the player cannot escape the screen). The character has a rigidbody and a box collider attached and the walls have a box collider attached(with the triggers turned off). The user must press the screen to allow the character to fly upwards (think doodle jump). The user will tilt the phone left and right to move the character left and right. When the character collides with either wall, the character will stop untill i tilt the opposite direction.

The Solutions:

1) At first, i was changing the transform of the character with the accelerometer and the touch. This would obviously cause errors with colliding, so i changed the transforms to AddForce. This worked perfectly on the walls when colliding, the character was sliding up and down the walls, BUT, the accelerometer moving was all wrong. The character was too slow at either tilt and taking too much time to gain speed. Not only that i could not tell the forces to stop completely, or reset, to move the other directions (sort of snapping effect).

2) I moved away from AddForce and tried out velocity. This works likes a charm, it has my snapping effect and the character moves at a decent set speed. The problem of the walls has come back though. So a success with a failure.

3) Since i liked the velocity "style of movement", i want to keep it, so my thoughts on correcting this issue with the walls were to create an additional 2 box colliders on the walls, but moving them in by 1 into the scene view. These box colliders are put here so that when the character triggers them (moves into them), the velocity will equal nothing, thus stopping the character stopping on the wall and when the player moves the character in the opposite direction, the velocity is equaled to its default state. This works perfectly!....but only on the left wall. The right and left wall, are mirrored, they are 100% the same. Just when the character collides with the right wall, the problem comes back.

The Code:

The Player:

 var jumpo: GameObject;
 var TiltSpeed: int = 50;
 var tileAngle: Vector3;
 static var anint: float = 0.0;
 var thetext: GUIText;
 var speedtext: GUIText;
         
 function Update()
 {
     //var tiltAngle = Vector3.zero;
     tiltAngle = Vector3.zero;
     tiltAngle.x = Input.acceleration.x;
     
     if(tiltAngle.sqrMagnitude > 1)
     {
         tiltAngle.Normalize();    
     }
     //tiltAngle *= Time.deltaTime;
     tiltAngle *= TiltSpeed;
     anint = tiltAngle.x;
     
     thetext.text = ""+(tiltAngle.x).ToString("f2");
     speedtext.text = ""+(TiltSpeed).ToString("f2");
     
     if(changeaxis.thebool == true)
     {    
         if(tiltAngle.x <= -1)
         {
             jumpo.rigidbody.velocity.x = 0;
         }
         else if(tiltAngle.x >= 1)
         {
             jumpo.rigidbody.velocity.x = anint;
         }
             
     }
     if(changeaxisright.thebool == true)
     {
         if(tileAngle.x >= 1)
         {
             jumpo.rigidbody.velocity.x = 0;
         }
         else if(tiltAngle.x <= -1)
         {
             jumpo.rigidbody.velocity.x = anint;
         }
     }
     
     if(changeaxis.thebool != true && changeaxisright.thebool != true)
     {
         jumpo.rigidbody.velocity.x = anint;    
     }
     
 }

The Left Wall:

  var jumpo: GameObject;
  var wall: Collider;
  static var thebool = false;
  var thetext: GUIText;

function OnTriggerEnter() { thebool = true;
}

function OnTriggerExit() { thebool = false;
}

function Update() { if(thebool == true) { thetext.text = "true"; } if(thebool == false) { thetext.text = "false";
} }

The Right Wall:

The right wall code is EXACTLY the same as the left wall, just the javascript file is called differently.

Some Ideas:

I do have some ideas, like reverting back to the AddForce method, but, is there a way to completely STOP the character from moving in the current direction to avert in the opposite direction, while its in "mid-air"? OR Attempt to carry on the way i am going. I have been stuck with this problem for a few days now, so any help would be brilliant! Hopefully i made sense in this question. I can explain further if need be.

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

2 People are following this question.

avatar image avatar image

Related Questions

Why does this MeshCollider think it's half as thick? 2 Answers

Continuously moving rigidbody 2 Answers

Major issues with physics 1 Answer

Stopping my player from moving when hitting a wall. 5 Answers

How to get collisions on Character controller? 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