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 horus developer02 · Dec 27, 2013 at 12:36 PM · movementpositiongravitymovetowards

Invert gameobject movement gradually when reaching a certain Vector3

I'm working on a 2D game and I have a script to move an object to a certain position with a constant speed using Vector3.MoveTowards but now, I need to simulate gravity in order that it reverts the direction of the object when it reaches a certain "limit" on Z axis.

I could use a fixed value for gravity but the problem is that the speed of my object can be something between 10 and 20 when it starts moving...

Here's an image demonstrating what I want:

Example

So, how can I do that? Is there any way to get the value of gravity to use in order that the object inverts on the given "limit" based on it's speed?

example.png (4.0 kB)
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
0
Best Answer

Answer by sparkzbarca · Dec 27, 2013 at 02:21 PM

so you want to make sure the objects fall mirrors its rise?

SOURCED:: http://forum.unity3d.com/threads/12588-Projection-Trajectory-Arc

     function GetQuadraticCoordinates(t : float) : Vector3 {
         return Mathf.Pow(1-t,2)*p0 + 2*t*(1-t)*c0 + Mathf.Pow(t,2)*p1 ;
     }
 
 
 where:
 p0 - is the start point
 p1 - is the end point
 c0 - is the middle point ( controlling the arcness )
 t - between 0 and 1
 
 
 so use the equation
 
 void update()
 {
 transform.position = vector3.slerp(currentPos, getquadcoordiantes(speed * time.deltatime), 1);
 }

that should work I think

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 horus developer02 · Dec 27, 2013 at 02:27 PM 0
Share

So, p0 is my bottom right point of the curved line in the image? But what about the other two? Which one is the value of "limit"? And I don't have the value of the bottom left point. I want it to be calculated automatically.

avatar image sparkzbarca · Dec 27, 2013 at 07:22 PM 0
Share

limit is the midpoint you calculate

you can yourself autocalculate the endpoint

endpoint is

 int Xmod;
 int Zmod;
 
 if(startpoint.x > midpoint.x)
 Xmod = startpoint.x - midpoint.x
 else
 Xmod = midpoint.x - startpoint.x
 
 if(startpoint.z > midpoint.z)
 Zmod = startpoint.z - midpoint.z
 else
 Zmod = midpoint.z - startpoint.z

that gets you the distance between the start and mid which is half way

now we double that to get the end pos

so

 endposition.set(startposition.x + Xmod * 2, startposition.y, startposition.z + Zmod * 2);

that gets us the end.

this assumes you figured out the co-ordinates of the mid. I dont know what your wanting enough to know how you find that but yea i mean its the mid point you decide on, its the limit point.

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

19 People are following this question.

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

Related Questions

Make object jump to fixed y position 1 Answer

Setting target position in Vector3.MoveTowards 2 Answers

Object "crawling" over floor, how? 2 Answers

Clamping object movement in circle 1 Answer

Facing the players game object (upward, downward, left, right) on Android phone using joystick 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