Objects "jump" with expressions

Objects "jump" with expressions

samunawa
Enthusiast Enthusiast
549 Views
1 Reply
Message 1 of 2

Objects "jump" with expressions

samunawa
Enthusiast
Enthusiast

Hi there. For my university project, I'm making a space system generator. So far I've managed to get everything working but I decided to create a small spacecraft which will be used to fly around with.

 

To do this, I created an expression for its X movement as shown below:

e05181a435ec41dbb2a293160462d291

 

 

I've also hooked this up to a slider which you can set the speed and hit a button to apply that speed setting as shown below (apologies for the crap GUI):

b7ac3d3817e64e28b18a252946a1470d

 

 

Now my issue is this, whenever I hit play and i set the speed to something and then i change it to another value, the spacecraft "jumps". Heres what I mean:

7200a762c358632bbf8a3b7d82b163d3

 

Is there a way to fix this issue? Heres my code for this:

 

 

//NAME: Saif Ahmed Munawar
//UB NUMBER: 15010505
//SUBMISSION: Final Project Submission

//Solar System Generator\\
//Spaceship Flight Script\\
//This script opens a new window which contains the controls for controlling the spacecraft\\
//I decided to make this seperate since the main GUI would get too clogged up so having a seperate GUI
//would be a more appriopiate thing to do\\

global proc throttle()
{
			global float $throttle;
			$throttle = `floatSliderGrp -q -v spaceship_speed`;
			$throttle = $throttle*10;
			print($throttle);
}
global float $throttle = 0.0;


{
 
string $spaceship = `window -t "Spaceship Controller" -wh 500 500`;
            frameLayout  -collapsable true -collapse false -label "Timeline & Misc" -bgc 0.5 0.1 0.1;
                    gridLayout -cellWidthHeight 400 25;
			            floatSliderGrp -label "THROTTLE" -field true -min 0 -max 10 -value 0 -step 1 spaceship_speed;
  	setParent..;	
	
					gridLayout -cellWidthHeight 584 25;
						button -label "Set Speed" -command "throttle()";	
						
showWindow $spaceship;

}

 

 

0 Likes
550 Views
1 Reply
Reply (1)
Message 2 of 2

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

The expression you are using is based on average speed. Once you've modified average speed, the position will be changed immediately, that's why you've spotted the jump.

 

To make it working, the expression should be newPosition = oldPosition + deltaTime * throttle

 

Yours,

Li

0 Likes