• 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 wbl1 · Feb 23, 2011 at 08:59 PM · movementaccelerationanimationcurve

moving in a straight line, but variable speed

So I am moving a car in a straight line but I want it to accelerate up to a maximum speed. I am thinking that animationCurve is a good way to go, but am not exactly sure how to execute this. How would I set up an animationCurve and use it to drive the car's transform?

Expanding a bit:

at t=0 sec, xPosition = 0 at t=1 sec, xPosition = 0.5 at t=2 sec, xPosition = 1.5 at t=3 sec, xPosition = 4.5

... and so on. Was thinking these values for t and xPosition would simply represent the keyFrames in an accelerationCurve. Does this sound right? If so, could anyone throw together some quick code to show me how to do this?

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
1
Best Answer

Answer by PrimeDerektive · Feb 23, 2011 at 09:13 PM

Hmm, that sounds like a terrible idea. To accelerate up to a maximum velocity, I would make the car object a rigidbody and do something like this (very basic example):

var accel : float = 3.0; var maxSpeed : float = 30.0;

function FixedUpdate(){ if(rigidbody.velocity.magnitude < maxSpeed) rigidbody.AddForce(Vector3.forward*accel); }

Comment
Add comment · Show 3 · 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 wbl1 · Feb 24, 2011 at 02:21 PM 0
Share

But, if I changed the example to something other than velocity, acceleration etc (thus we did not have the physics engine), would this be an appropriate use of accelerationCurve. I am just trying to understand what its about ... Thanks

avatar image PrimeDerektive · Feb 24, 2011 at 02:53 PM 1
Share

Then I would use transform.translate, and do a similar thing (but you'd have to measure velocity yourself). Animation curves are for animated models with animation clips (for instance, a human model with a walk animation or a punch animation). I wouldn't handle actual movement with animations.

avatar image wbl1 · Feb 24, 2011 at 06:25 PM 0
Share

O$$anonymous$$, thanks. Appreciate your help!

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Ball Rolling System 1 Answer

Character Motor: standard vs. custom ? 0 Answers

Using Animation Curve for Movement Help 1 Answer

How to Tilt a Spaceship Based on Inertia/Acceleration Force Separate from Facing Direction? 2 Answers

Does anyone know what i am doing wrong? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges