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 ricardoluz19 · Jun 17, 2020 at 05:38 PM · 2dmove an objecttimescale

Object movement with different time scale

Hi everyone,


I am making a top down game in 2d where the player is a car. If you press the right mouse button, the car will "jump" to a certain height which is implemented by increasing the y pos with a height delta that gives the illusion that the car is jumping. This is how it is implemented:


bodyTransform.position = new Vector3(bodyTransform.position.x, bodyTransform.position.y + heightDelta, bodyTransform.position.z);


I am now implementing a feature where, if you press the spacebar, the game will be in slow motion. I implemented this by just reducing the timescale of the game until a value let's say 0.3f.


In slow motion, the normal movement of the car is slowed down, but when I jump, the car just jumps at normal speed.


I tried to multiply the "heightDelta" variable with the "Time.deltaTime" which worked fine for the normal movement, but for jumping, the normal speed is kept and it's only reducing the height of the jump since "Time.deltaTime" is lower when the timescale is lower.


I am doing the movement of the car in the Update function because the movement in slow motion is much smoother than in FixedUpdate


Does anyone have an idea how can I implement the slow motion for the jump?


Any clue would be a great help.


Thank you very much
Ricardo

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

Answer by ricardoluz19 · Jun 22, 2020 at 02:29 PM

Hi Everyone,

I have managed to found the solution if this can help anyone in the same situation.

Basically I knew that I had to relate the heightDelta with the the Time.DeltaTime somehow, but if I multiply it directly in the instruction above (in the position update), the car when in slow motion will just jump lower as the Time.DeltaTime is smaller with a smaller Time.TimeScale.

The solution was to use the Time.DeltaTime as I am calculating the heightDelta. To calculate the jump trajectory I am using a parabolic equation like:

h = -t^2 + (ti+tf)*t - ti*tf + h0 where (ti,h0) is the initial jump height and time instant.
Let's consider that the car is jumping from the current car position and we start to measure time from the instant we jump, so we can consider (ti,h0) = (0,0). The tf is the duration of the jump we want. With this we endup with: h = -t^2 + tf*t.

Refer to this page where I found similar information: https://answers.unity.com/questions/1113304/how-can-make-my-player-to-jump-like-parabola.html

From this point we can simply replace t by the current Time.DeltaTime to get the height value.

As the car position is being calculated by using the current position itself, I cannot use the height directly coming from the above equation because we will be always adding positive values which will make the car only go up but will not go down.
What we need to do is to calculate the heightDelta that will be result from recursively subtracting the previous from the current height: heightDelta = h(n) - h(n-1)

With this we can use different time scales and still mantain the same behaviour when jumping.

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

272 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 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 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Move object from point a to point b 1 Answer

(2D) Game runs faster when quality is set to low 1 Answer

Move a object to certain cordinates 2 Answers

2D- Move bullet in every direction 1 Answer

Assets/Scripts/PlayerController.cs(32,49): error CS0126: An object of a type convertible to `float' is required for the return statement 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