• Increase font size
  • Default font size
  • Decrease font size
Welcome, Guest
Username Password: Remember me

Constant Acceleration
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: Constant Acceleration

Constant Acceleration 4 years, 9 months ago #808

  • AmishRob
  • Fresh Boarder
  • Posts: 5
Hi all, I just downloaded Physion earlier today and I really like it already. I am attempting to build simulations that involve a car starting at rest and gradually increasing its velocity with a constant acceleration.

I have successfully built a car that rolls at a constant velocity, but I'm not sure how to use scripting to increase the MotorSpeed variable of both Revolute Joints by a constant amount for every set increment of time (Counter variable).

I read the intro to scripting and I believe it can be some modified version of the OnUpdate example, but I really don't know JavaScript (yet:). For my specific example, I'd like to start at rest and accelerate to the right increasing the motor speed 2 cm per second every 10th of a second.

Thanks in advance.

Re: Constant Acceleration 4 years, 9 months ago #809

  • Lynxx
  • Moderator
  • Java/C#-Developer
  • Posts: 223

OnUpdate wouldn't be a good idea, because it's called after all calculations finished for one frame, this means a more complex scene will less often call OnUpdate.

For exact timing it's better to use QTimer, here is a little example with increases the motorspeed 0.02 every 1/10 second (code placed in OnStart of any object):

this.timerevent = function() {
if (world.running()) {
this.motorspeed += 0.02;
motor1.MotorSpeed = this.motorspeed;
motor2.MotorSpeed = this.motorspeed;
this.Text = "Speed: "+this.motorspeed;
this.motorspeed = 0;
this.timer = new QTimer();
this.timer.interval = 100;

Here is an example-scene using this code:

This image is hidden for guests. Please log in or register to see it.

Download it and save it to Physion-Folder/data/saves

Have phun.
Infinity is vast, especially near end.
bye, Lynxx

Re: Constant Acceleration 4 years, 9 months ago #810

  • AmishRob
  • Fresh Boarder
  • Posts: 5
Thanks, so much Lynxx.

The script works well. I need the entire sequence to happen more quickly for the car to get up to speed, but if I increase the the line that says
this.motorspeed += 0.02; to something higher (e.g. += 0.1;), the car ends up lifting off the track. I may just use the script you suggested, record the action on screen, and speed up the clip to fit my needs.

Thanks again.

Re: Constant Acceleration 4 years, 9 months ago #811

  • AmishRob
  • Fresh Boarder
  • Posts: 5
I actually found a much simpler solution for my purposes. I just set gravity along the x-axis to a positive value, which generate the positive acceleration that I needed without the additional problems I noted below.
  • Page:
  • 1
Moderators: Lynxx, Glenn555
Time to create page: 0.11 seconds