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 ud3p · Apr 12, 2015 at 11:47 AM · 2dcollisioncolliderrigidbodiesfast

Fast moving objects 2D game

Hey guys!

I find the official unity training https://www.youtube.com/watch?v=D5MqLcO6A8g and find bug.(look at the score)

I spent about 2 days to fix it and failed. I find the script http://wiki.unity3d.com/index.php?title=DontGoThroughThings and try to rewrite to use in 2D. Failed again)

Please help me!

This is rewrite script:

 using UnityEngine;
 using System.Collections;
 
 public class DontGoThroughThings2D : MonoBehaviour {
 
     public LayerMask layerMask; //make sure we aren't in this layer 
     public float skinWidth; //probably doesn't need to be changed 
     
     private float minimumExtent; 
     private float partialExtent; 
     private float sqrMinimumExtent; 
     private Vector2 previousPosition; 
     private Rigidbody2D myRigidbody; 
     
     
     //initialize values 
     void Awake() 
     { 
         myRigidbody = GetComponent<Rigidbody2D>(); 
         previousPosition = myRigidbody.position;
         minimumExtent = Mathf.Min(Mathf.Min(GetComponent<Collider2D>().bounds.extents.x, GetComponent<Collider2D>().bounds.extents.y)); 
         partialExtent = minimumExtent * (1.0f - skinWidth); 
         sqrMinimumExtent = minimumExtent * minimumExtent; 
     } 
     
     void FixedUpdate() 
     { 
         //have we moved more than our minimum extent? 
         Vector2 movementThisStep = myRigidbody.position - previousPosition; 
         float movementSqrMagnitude = movementThisStep.sqrMagnitude;
         
         if (movementSqrMagnitude > sqrMinimumExtent) 
         { 
             float movementMagnitude = Mathf.Sqrt(movementSqrMagnitude);
             //RaycastHit2D hitInfo; 
             
             //check for obstructions we might have missed 
             if (Physics2D.Raycast(previousPosition, movementThisStep, movementMagnitude, 0, layerMask.value)) 
                 myRigidbody.position = (movementThisStep/movementMagnitude)*partialExtent;
             Debug.DrawLine(myRigidbody.position, myRigidbody.position - previousPosition, Color.green);
         } 
         
         previousPosition = myRigidbody.position; 
     }
 }
 

This is unitypackage https://www.dropbox.com/s/a3n1dalbc1k0k42/Hat%20Trick.unitypackage?dl=0

P.S. Sorry for my english and thank you for help!!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by TheRobWatling · Apr 12, 2015 at 01:46 PM

First thing to check is your rigidbody component in the scene. Check to see if it has its collision set to Continuious Dynamic rather than Dynamic or the other option. Unity suggests this for fast moving objects.

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 ud3p · Apr 13, 2015 at 10:03 AM 0
Share

I set Collision Detection "Continuous". I try different $$anonymous$$in Penetration for penalty. It did not help.

avatar image
0

Answer by Oriyus · May 16, 2015 at 04:40 PM

I just spent some time trying to solve this. For me what did the job is Edit/Project Settings/Physics or Physics2d and making Position Iterations 6 from 3(default).

I'm not sure how expensive this is but at least its working good :D .

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Colliders in a wall jut out 0 Answers

Collision with renderer.enabled? 0 Answers

Multiple Stacked Colliders only register for single object 0 Answers

Collider2D/RigidBody2D not working 1 Answer

2 isTrigger Colliders (2D) 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