Hello,
Let’s say that I have a cube in my scene and I then call the move method on that cube (Box).
How can I show the transition from old position to new position on the screen? That is to say I want to actually see the cube physically move from the old position to the new position after waiting a specified amount of time.
Would it be much more different or difficult to get the cube to move smoothly on screen in a line from a start position to an end position?
Thank you.
Just move it a bit at a time using tpf until it reaches its destination…
other possibilities are using FastMath.InterpolateLinear (), with old vector and new vector, and increment the count (shown in math for dummies)
or cinematics (recommended for cut scenes, not really for in game)
Can you give me a code example? You make it seem really easy and an example would show it more clearly.
How can I access tpf outside the update loop? If I do it inside the update loop would it not just repeat over and over again?
Thank for your help.
@wezrule said:
or cinematics (recommended for cut scenes, not really for in game)
You can use MotionEvent though. MotionEvent is a classic control that makes a spatial move along a MotionPath.
@tl888 if you just want to move from a position to another just do what @zarch said.
@tl888 said:
How can I access tpf outside the update loop? If I do it inside the update loop would it not just repeat over and over again?
make it stop when it should..
lets say you want it to last 5 seconds
[java]
float time = 0f;
public void simpleUpdate(float tpf){
if( time < 5f) {
cube.move(tpf, 0,0);
time+=tpf;
}
}
[/java]
Right ok (re: cinematics)
Heres an interpolate linear example, if you don’t wanna worry about directions or such likes, but either way is fine:
[java]
private boolean shouldMove = true;
private float count = 0;
private Vector3f start = spatial.getLocalTranslation ();
private Vector3f end = new Vector3f (14, 2, -10);
update (float tpf) {
if (shouldMove) {
count += tpf/10; //this will make it take 10 seconds to reach the end, from the the start
Vector3f newLocation = FastMath.interpolateLinear(count, start, end);
spatial.setLocalTranslation(newLocation);
if(count>= 1) //then you reached the end
shouldMove= false;
}[/java]
@tl888 said:
Yeah, what @zarch said seems like what I want to do but I don't know how to do it. Sorry, I'm new.
I recommend going through all the tutorials, because this is a very basic issue.
Thank you @wezrule @nehon
Can you tell me if there is a way to access tpf from outwith the main application class and the update method? I want to change the start and end vectors in another class and then call update again to make the cube move again. Is there a way I can do this?
I understand that the update method is automatically called. I’m just wondering if I can call it directly.
Thank you
@tl888 said:
Thank you @wezrule @nehon :)
Can you tell me if there is a way to access tpf from outwith the main application class and the update method? I want to change the start and end vectors in another class and then call update again to make the cube move again. Is there a way I can do this?
I understand that the update method is automatically called. I'm just wondering if I can call it directly.
Thank you
Please do the tutorials. You are making things extremely hard for yourself by trying to work around every established pattern.
@tl888 said:
Can you tell me if there is a way to access tpf from outwith the main application class and the update method?
put it inside a control/appstate, then you can access the update loop there, do not call it directly.