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 Maria.and.Irina.Popova · Jun 04, 2012 at 07:25 AM · physicscurve

Make an Object Responding to Physics

Hi all, I have been using the code below to make my character jump in a curve from one point to another. Found it somewhere in this site.

 function Update()
 {

 BezierTime = BezierTime + Time.deltaTime;

 if (BezierTime >= 1)
 {
     BezierTime = 0;
 }

 CurveX = (((1-BezierTime)*(1-BezierTime)) * StartPointX) + (2 * BezierTime * (1 - BezierTime) * ControlPointX) + ((BezierTime * BezierTime) * EndPointX);
 CurveY = (((1-BezierTime)*(1-BezierTime)) * StartPointY) + (2 * BezierTime * (1 - BezierTime) * ControlPointY) + ((BezierTime * BezierTime) * EndPointY);
 transform.position = Vector3(CurveX, CurveY, 0);

}

The code works perfectly, but what I want to achieve is make the object tp bounce (responds to physics) when it hits something.

Any suggestion please?

Thanks very much. [sorry for my bad english.]

Irina Popova

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 asafsitner · Jun 04, 2012 at 07:54 AM 1
Share

Perhaps a better way to implement this would be to actually use physics, then? Give the object a bouncy physics material, and it should bounce off obstacles.

Calculating the required force to make it jump in a nice curve might require some knowledge in physics, however.

avatar image Irina124 · Jun 04, 2012 at 09:37 AM 0
Share

I have tried using physics before but I could achieve that desired curve. In my game, I have a character that jumps to wherever user touch.. The further it is, the more powerful force added to the rigidbody using the Vector2 $$anonymous$$agnitude calculations. It works well with short ranged jumps, but it goes crazy with far jumps..

avatar image Maria.and.Irina.Popova · Jun 04, 2012 at 09:40 AM 0
Share

@asafsitner: Tell me about it :(

@HeyEveryCoder: my game its almost similar with yours, so have you figured out any solutions?

I have also tried applying rigidboy velocity in the update function. But it doesnt work.

Anyone have had encounter this problem before?

Thanks

Irina Popova

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Jun 04, 2012 at 10:57 AM

Well you could try a mixed solution. Attach a Rigidbody to your object, but make it kinematic, so the physics are disabled. Move it along the bezier curve, but you need a way to interrrupt the movement (e.g. a boolean variable). Just check for collisions with OnCollisionEnter. If you collide with something, stop your bezier movement, turn physics back on (isKinematic = false) and apply a starting force maybe just in the old movement direction.

From now on your player will react to physics. You have to find out when your player is back on ground to switch back to your old movement, but that's roughly the procedure.

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 Maria.and.Irina.Popova · Jun 05, 2012 at 05:15 AM 0
Share

Your suggestion sounds solid, but when i tried, it seems that I have trouble applying the needed force. $$anonymous$$aybe its just my bad math.

I gave up... I have posted a job on elance.com. Hope someone could do this job for us..

https://www.elance.com/job/30986011/proposals

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

2D 360 degress platformer example needed 0 Answers

Bomb Trajectory for a "Water Canon" (Maths) 1 Answer

Navigate Curve at Constant Speed 3 Answers

display arc for cannon's ball trajectory? 2 Answers

how to shot a soccer ball in curve path according to the swipe type 2 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