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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by MarvinH · Jul 18, 2012 at 03:29 AM · scaleplatformer

Is there a better way to simulate a vacuum or kirby like suction that doesn't kill frame rate?

Hello,

I'm trying to create the shrink/suction mechanic from Kirby or Luigi's Mansion. The Main character has a vacuum that he uses as a gun. Right now, we are using a Raycast that generates when the player presses the right mouse button down. If the Raycast hits a collider with a RigidBody, The ray shrinks the object, and draws it closer to the player. Here's the code: The great thing is, it works. The problem is if there is more than one enemy on screen, the frame rate falls way down.

My Question: Is there a better way to simulate a vacuum or kirby link suction that doesn't kill frame rate? Any Help would be amazing! Thanks.

     if(lastAtk + rateOfFire<=Time.time)
  {
  lastAtk=Time.time; //reset last time we attack to  put gap between attacks. (AKA rateof fire)
  print(&quot;bang!&quot;);
  //...draw a Ray cast forward
  var hit : RaycastHit;
  ray = new Ray (arm.transform.position, (targetPoint-arm.transform.position).normalized);
  Debug.DrawLine(arm.transform.position, targetPoint, Color.yellow,1);
  if (Physics.Raycast (ray, hit, range))
  {
  //print(hit.transform);
  //if ray collides with an enemy
  var hitTag = hit.collider.tag;
  if(hitTag=="Enemy")
  {
  //Debug.Log("enemy hit");
  
  
  hit.transform.gameObject.SendMessage("ApplyDamage",10,SendMessageOptions.DontRequireReceiver);
  
  print(transform.root.name+" attacked!");
  }
  
  //apply a force to the enemy to "suck"; them up
  //         if (hit.collider.attachedRigidbody) 
  //         {
  //         var dir : Vector3 =  arm.transform.position -hit.transform.position ;
  // dir = dir.normalized;
  //          hit.collider.attachedRigidbody.AddForce((dir) * power);
  //          //shrinks enemy
  //          var locScale: Vector3 = hit.transform.localScale;
  //          if(locScale.x&gt;=.1){hit.transform.localScale -= Vector3.one*Time.deltaTime*shrinkSpeed;}
  //          else{hit.transform.localScale=Vector3(.1,.1,.1);}
  //          }
  
  } 
  }

Here is the 'shrink' part of the code

     //apply a force to the enemy to "suck" them up
  //         if (hit.collider.attachedRigidbody) 
  //         {
  //         var dir : Vector3 =  arm.transform.position -hit.transform.position ;
  // dir = dir.normalized;
  //          hit.collider.attachedRigidbody.AddForce((dir) * power);
  //          //shrinks enemy
  //          var locScale: Vector3 = hit.transform.localScale;
  //          if(locScale.x&gt;=.1){hit.transform.localScale -= Vector3.one*Time.deltaTime*shrinkSpeed;}
  //          else{hit.transform.localScale=Vector3(.1,.1,.1);}
  //          }

 


Comment
Add comment · Show 3
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 Frischt1421 · Dec 11, 2015 at 02:21 PM 0
Share

Was this ever figured out?

avatar image Frischt1421 · Dec 11, 2015 at 03:09 PM 0
Share

Did you ever find an answer to this?

avatar image tanoshimi · Dec 11, 2015 at 07:11 PM 0
Share

Yes - use the profiler...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by VIDesignStudios · Dec 08, 2016 at 10:17 AM

How about dropping the raycast altogether and having a simple trigger box or sphere always out in front of the character, waiting for collisions with tagged enemies, and this trigger box collider only turns on / game object activates when the right mouse is pressed? After a hit is detected, you could remove the Rigidbody right before shrinking so it doesn't pain the physics engine.

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

6 People are following this question.

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

Related Questions

Do I need to use tiling on sprite game object? 1 Answer

2D 360 degress platformer example needed 0 Answers

My character rescales under any object 1 Answer

Maya to Unity Scale Factor Issues 0 Answers

How to get expanding object collide when it touches others? 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