1
0
forked from 0ad/0ad
0ad/binaries/data/mods/public/simulation/components/MotionBall.js
Ykkrosh 7c2e9027c2 # Rewrite of the game's simulation system
Giant merge from
http://svn.wildfiregames.com/hg-source/file/5fb522019d5e
Infrastructure is largely complete, gameplay is largely missing
Disabled by default; use command-line flag "-sim2"
(Second attempt at commit...)

This was SVN commit r7259.
2010-01-09 19:20:14 +00:00

33 lines
832 B
JavaScript

function MotionBallScripted() {}
MotionBallScripted.prototype.Init = function() {
this.speedX = 0;
this.speedZ = 0;
};
MotionBallScripted.prototype.OnUpdate = function(msg) {
var dt = msg.turnLength;
var cmpPos = Engine.QueryInterface(this.entity, IID_Position);
var cmpTerrain = Engine.QueryInterface(SYSTEM_ENTITY, IID_Terrain);
var pos = cmpPos.GetPosition();
var normal = cmpTerrain.CalcNormal(pos.x, pos.z);
var g = 10;
var forceX = normal.x * g;
var forceZ = normal.z * g;
this.speedX += forceX * dt;
this.speedZ += forceZ * dt;
var drag = 0.5; // fractional decay per second
this.speedX *= Math.pow(drag, dt);
this.speedZ *= Math.pow(drag, dt);
cmpPos.MoveTo(pos.x + this.speedX * dt, pos.z + this.speedZ * dt);
};
Engine.RegisterComponentType(IID_Motion, "MotionBallScripted", MotionBallScripted);