ambiera home ambiera home

Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name:  Password:
Ambiera Forum > CopperLicht
Smooth movement
Author Text

Registered User
2017-12-15 22:10:05


I would like to move a scene node left and right on the X axis.
I'm using the code from the tutorial but I have noticed the movement is not smooth.

What I mean, when I press a key down, the object move once then stop for a moment then continue the movement but the movement is a bit lumpy like the FPS would be low or the scene would be not rendered every frame.

I tried to find a way to set FPS in CopperLicht but I didn't find anything in the doc, maybe I was looking the wrong place. However, inside CopperCube in the scene settings I did increase the max FPS to 60 and to redraw the screen every frame. But it didn't help.

This is the code I'm using:

var player_speed = 1;
var player_leftkey = 'A';
var player_rightkey = 'D';

engine.ingComplete = function()
var scene = engine.getScene();
if (scene)
playerSceneNode = scene.getSceneNodeFromName('player');



document. = function(event)
var key = String.fromCharCode(event.keyCode);

if (key == player_leftkey && playerSceneNode)
playerSceneNode.Pos.X += player_speed;

if (key == player_rightkey && playerSceneNode)
playerSceneNode.Pos.X -= player_speed;


Since, it seems like there is no physics to move anything, I don't know what else I could try.

Any help on this would be appreciated.

Thank you.

Registered User
2017-12-16 19:16:05

You don't need physics for this, you could make it smooth by just accelerating the player_speed over time.

Registered User
2017-12-16 20:24:40

Thank you, but I think it a compatibility problem with my GPU rather:

Registered User
2018-05-19 21:20:02

Hello ddabrahim, I don't fully know what your code is doing since it seems to have been ruined by the forum's security, so I will tell you what I did.

I also noticed a problem with smooth movement, so I do this:

1. I don't put the actual movement in the "on key up" and "on key down" portions. I use those only to set a variable to "true" or "false".

If the button is pressed, I put this:
ShouldCharacterMoveLeft = true;

If the button is released, I put this:
ShouldCharacterMoveLeft = false;

2. I put my actual movement in a function called "OnAnimate", like this:
engine.OnAnimate = function() 
if (ShouldCharacterMoveLeft == true)
moveVect = new CL3D.Vect3d(0,0,-1);
PositionOfCubeNode = cubenode.Pos;
newposition = cubenode.Pos.add(moveVect);
cubenode.Pos = newposition;

If the variable called "ShouldCharacterMoveLeft" is set to "true", the character will move. All pieces of code inside of the "OnAnimate" function will happen during every frame, so the movement will be smooth.

Create reply:

Posted by: (you are not logged in)

Enter the missing letter in: "Inter?ational" (you are not logged in)




Forum Codes

Feature Code
Link [url] [/url]
Bold [b]bold text[/b]
Image [img][/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]



Software: Ambiera Light Forum. © 2008-2019 Nikolaus Gebhardt, Ambiera e.U.