Implementing Smooth Movement and DeltaTime in Game

Software: Away3D 4.x

rustyk, Newbie
Posted: 26 March 2016 04:17 AM   Total Posts: 22

Hi,

I’m porting a simple game from another engine that uses some kind of equalizing speed so it will be the same regardless of sytem spec.

I found there’s a solution in 2D (Starling) but not sure how this would be something similar with Away3D.

private function update(e:EnterFrameEvent):void
{
    deltaTime 
e.passedTime//passedTime is starling attribute
}

...

Player.+= movementSpeed deltaTime

I know there’s deltaTime for Away3D but I’m not sure how to use it. I can’t find any examples on web either (yet).

 

 

   

Yann, Newbie
Posted: 31 March 2016 09:28 AM   Total Posts: 16   [ # 1 ]

Hello,

I’m not sure of what I’m going to write so I think you should wait for a confirmation
but
if you use an “animator” class ( for exemple the skeleton animator ) the motion is based on the time given by the function getTimer()

in the animatorBase.as :

private function onEnterFrame(event:Event null):void
  {
   update
(getTimer());
  

You can find some information about the getTimer here
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#getTimer()

but basicaly it returns the time spent since your application is runing. Whatever the system specs are.
So if your issue is to be sure that the motion will have the same speed on all the systems, you can trust in the animator class or build your own class based on the time returned by this function.
I hope this can help you

   

rustyk, Newbie
Posted: 01 April 2016 01:57 AM   Total Posts: 22   [ # 2 ]

Thanks. I was wondering why the above is not hooked in the player movement?

   

therealloft, Member
Posted: 01 April 2016 07:30 AM   Total Posts: 65   [ # 3 ]

This is what i would use

private var view:View3D;
protected function 
update(event:Event):void
{   
 view
.camera.moveForward(view.deltaTime 10); //move camera forwards 10 meters per second
 
view.render();
   

rustyk, Newbie
Posted: 01 April 2016 02:18 PM   Total Posts: 22   [ # 4 ]

Hey thanks therealloft! So I can just do the same for let’s say AI like this?

enemy.moveForward(enemy.deltaTime 10

this sure helped a lot.

 

   

therealloft, Member
Posted: 01 April 2016 04:25 PM   Total Posts: 65   [ # 5 ]

if you create a public static var to hold it, it be easyier like this

public static var deltaTime:uint 0;

protected function 
update(event:Event):void
{
 view
.render();
 
deltaTime view.deltaTime;

Then all you have to do from any part of you app to find deltaTime is call

Main.deltaTime 

hope this helps

   

rustyk, Newbie
Posted: 03 April 2016 01:29 AM   Total Posts: 22   [ # 6 ]

appreciate this added tip therealloft. will definitely try this out, thanks!

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X