## Recommended Posts

i need a reverse of this in affect; (bullet trajectory example)

http://gamemechanicexplorer.com/#bullets-5

I need bouncing from tile to tile, and sometimes skipping tiles. It needs to be exact.  in cocos2d , it's as easy as saying jumpTo(x,y);

The example fires off from an angle.. I need to workout that angle and power to fire off (if using physics)

Any ideas?

##### Share on other sites

Still struggling, I found these,

http://www.mathisfunforum.com/viewtopic.php?id=1673

http://en.wikipedia.org/wiki/Trajectory_of_a_projectile#Angle_required_to_hit_coordinate_.28x.2Cy.29

Trouble is im finding it hard to translate, I dont know time, as i want the physics engine to do it; I know the distances, i dont know velocity or angle. Time is irrelevant;

`            var theta = 60;            var x = 0, y = 0;            var t = 10;            var GRAVITY = 980;            var xdist = 32, yHi = 0;            x = xdist / Math.cos(theta);            y = x * Math.sin(theta) - 0.5 * GRAVITY * t * t;            x = xdist / (x * theta);            y = yHi / (y * theta);            this.body.gravity.set(0, GRAVITY);                        this.body.velocity.x = (x );            this.body.velocity.y = (y );`
##### Share on other sites

i came up with this; it works pretty well; makes an arc

but it is totally not accurate and you need to fid

`        bounceTo(targetPoint: Phaser.Point, direction?: Game.DirectionType) {            if (direction) {                this.direction = direction;            }            this.targetPoint = targetPoint;             var gravity = 519.81;            this.body.gravity.set(0, gravity);            var duration = 0.5;            var VOx = ((targetPoint.x - this.position.x) / duration);            var VOy = ((targetPoint.y + 0.5 * gravity * duration * duration - this.position.y) / duration);            if (this.direction == Game.DirectionType.UP) {               // console.log(((this.position.y - targetPoint.y) / 16) * 2);                                this.body.velocity.y = -VOy * ((this.position.y - targetPoint.y) / 16) * 2;;            }            else {                this.body.velocity.x = VOx;                this.body.velocity.y = -VOy;            }             this.state = Game.States.STATE_BOUNCING;        } `

any advice to improve would be much appreciated

dle with the gravity and time.  and needs further fiddling for starting at different heights

edit: note for different heights ONLY i also got good results by tweening,

`            // Move the ball vertically by the easing function            this.game.add.tween(this).to({ y: this.targetPoint.y },                2000, Phaser.Easing.Quartic.In, true, 0, 0);            // Move the ball vertically by the easing function            this.game.add.tween(this).to({ x: this.targetPoint.x },                2000, Phaser.Easing.Linear.None, true, 0, 0); `

the speed slows down (tweens),m how can i make a tween constant speed?