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 Kk1496 · Mar 12, 2015 at 03:35 AM · c#collisioncollision detection

No collision detection when using special abilities

I made a script that would allow the player to speed up after collecting an item. Baically, it multiplies the players speed by 2 when the player presses the button However, the collision detection doesn't seem to work when the player has the speedup ability and passes through walls.

 public class Red_PickUp : PickUp
 {
     public float boostTime = 2.0f;
     public float multiplySpeed = 10.0f;
 
     private float timer;
     private float speedUp;
     private bool used;
 
     new void Start ()
     {
         base.Start ();
         used = false;
         timer = boostTime;
         speedUp = player.moveSpeed * multiplySpeed;
     }
 
     void Update () 
     {
         SpeedUp ();
 
         if (used)
         {
             timer -= Time.deltaTime;
             Debug.Log (timer);
             player.moveSpeed = speedUp;
 
             if (timer <= 0)
             {
                 timer = 0.0f;
                 player.moveSpeed /= multiplySpeed;
             }
         }
     }
 
     void SpeedUp ()
     {
         if (player.collected.Contains (this.gameObject))
         {
             if (Input.GetKeyUp (KeyCode.Z)) {
                 used = true;
             }
         }
     }
 }
 
Comment
Add comment · Show 4
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 AlwaysSunny · Mar 12, 2015 at 02:54 AM 0
Share

I don't exactly grasp your logic flow; it seems a little dangerous. That said, I don't see anything that would break physics.

Are you perhaps increasing your speed so much that objects are ghosting through colliders? This occurs when you apply a force or request a translation that would move the player a distance greater than the thickness of an obstacle. In such instances, (like with fast-moving projectiles) it's often necessary to supplement the physics sim with some raycasting checks to ensure you don't zip right through walls.

avatar image Kk1496 · Mar 12, 2015 at 03:09 AM 0
Share

The players speed is set to three and $$anonymous$$ultiplySpeed is set to 10, so the speed becomes 30? that doesn't seem like it makes it unreasonably fast. my walls are cubes that are scaled by 1 in thickness. So, would making my walls thicker make a difference. How would I work with this if I imported models? Do you have any ideas for how I can make the logic more reasonable. Basically, when this object is picked up and the player presses the button, the speedup occurs for 2 seconds.

avatar image AlwaysSunny · Mar 12, 2015 at 03:29 AM 0
Share

A speed of 30 units per second is somewhat outrageous if your average obstacle is 1 unit thick. (In a single physics step, your player can move more than 1 unit. This is a recipe for this exact issue).

I suspect this "ghosting" or penetration error is to blame for your troubles. This is a well-known phenomenon for which there are many potential solutions. (Google is your friend).

To some degree, you must limit the mechanics of your game to comply with what the physics simulation is capable of. That said, there are settings at your disposal which can improve the stability and accuracy of the simulation at the cost of performance. See the documentation regarding physics and its associated settings.

Regarding your logic, I suppose if it works, it's fine. I am just picky and particular about how I approach problems. You'll develop stronger practices as you learn.

Regarding your pickup that last for two seconds, it seems like an ideal opportunity to learn about Coroutines. But here again, if it works, just leave it be and you'll pick that topic up when you're ready.

avatar image Kk1496 · Mar 12, 2015 at 04:38 AM 0
Share

Thanks a lot! :) I'll try slowing him down a bit (maybe a speed of 15 is more reasonable?). Amd I'll look into corputines when I go back and optimize things.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Not detecting collision? 1 Answer

Child Collides If Its The Parents Collider 0 Answers

Check for collision while animating 0 Answers

Destroying object on collision 3 Answers

How to stop object from going through walls. 4 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