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
0
Question by pikpiak · Jul 11, 2011 at 04:46 AM · knockbackplanetary

Knockback along curved surface.

I am currently using a SlamBack function to knock my avatar back.

 function SlamBack ( slamDistance : Vector3 )
     {
         var controller : CharacterController = GetComponent(CharacterController);
         var slamTime = Time.time;
     
         while ( slamTime + 0.5 > Time.time )
         {
             controller.Move ( slamDistance * ( slamTime + 0.5 - Time.time ) / 0.5 * Time.deltaTime );
             yield;
         }
     }

And codes to simulate planetary gravity while moving in Update.

 if ( !Physics.Raycast ( transform.position, -transform.up,  1.1 ) )
 {
     ground = 0;
     faux += ( transform.position - Vector3.zero ).normalized * -0.5 * Time.deltaTime; //apply gravity
     controller.Move ( faux );
 }
 else
 {    
     ground = 1;
     faux = Vector3.zero; // reset gravity
 }

 QuaternionRotation = Quaternion.FromToRotation ( transform.up, ( transform.position - Vector3.zero ).normalized );
 transform.rotation = QuaternionRotation * transform.rotation;

The end result i get when player gets knocked back is, it will move in a straight line backwards, leaving him off the curved planet surface, then dropping down from the gravity. I was wondering if I can fine tune it so that it gets knocked back along the surface instead. Will appreciate any tips, thanks.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by testure · Jul 11, 2011 at 05:28 AM

the first thing that comes to mind is that you could first calculate the knock back force on a given frame, and make sure that it's clamped within a certain velocity so that it doesn't escape the planetary gravity. Because what you've described is essentially what should happen.. if gravity is not strong enough to counteract the thrust, you should be able to shoot something right out of orbit... basic rocketry ;)

But yeah, if you clamp that velocity per frame, it would do the trick. it might look strange, however- since it wouldn't necessarily have the same 'force' to it.

The only other thing I can suggest is to increase the gravity that you're applying based on the knockback velocity.. that way if the force is too strong, you increase gravity to counteract it.

Comment
Add comment · Show 2 · 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 pikpiak · Jul 11, 2011 at 04:52 PM 0
Share

ok I tried adding the gravitational controller.$$anonymous$$ove line below to counteract it every frame calculation during knockback function, like this:

controller.$$anonymous$$ove ( slamDistance ( slamTime + 0.5 - Time.time ) / 0.5 Time.deltaTime ); controller.$$anonymous$$ove ( faux );

It works with some slight shaking. Thanks.

avatar image testure · Jul 16, 2011 at 12:24 AM 0
Share

If this worked out for you, please mark it as "accepted", it will help others with similar questions.

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

Player Knockback / PushBack 2 Answers

Enemy Knockback when hit player 2D Topdown 1 Answer

Trying to make my Player's sword knockback the enemy without making the enemy animation freak out. 0 Answers

Fire Knockback, Vectors, Directions 1 Answer

Triying to make a character take knockback in a parabolic motion in 2D. 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