December 18, 2017, 01:07:30 am

News:

Welcome to the Platino support forum!
Platino 4 updates will be coming before the end of the year.  Check back soon!
--December, 2017


Infinite Runner Player Movement. How to?

Started by Couds, September 08, 2015, 04:20:24 pm

previous topic - next topic
Go Down

Couds

Hey guys. this may be a silly question. but Im trying to do a infinite runner (My first video game) but I can't get the "player" to start running. >.<. I added my scene code to the attachments.

the scene.stepDelta method is called on every enterframe event. I tried to do a runner.state.vel.set(1,0) but didn't work, same with acc. If I use the pos runner.state.pos.add(speed*delta,0) the physics don't work.

Can anyone help me? Im really a new in game develop :/

Thanks to all ^.^
My code don't have bugs.. just random and erratic behaviour..

peachpellen

September 09, 2015, 12:24:38 pm #1 Last Edit: September 13, 2015, 11:50:58 pm by johngould
This should be better documented, I'm making a note to myself... but I don't see

Code Select
game.enableOnDrawFrameEvent = true;

From here.

In your code anywhere there. Are you setting it elsewhere? Please let me know. If there's no change I will ask Joseph (a core engineer who has far more experience with PhysicsJS than I do) to check this out.

- Peach :-)

*Edited: I wanted to add the link to the appropriate API in the docs.

Couds

Hi Peach.

I already have that enable in the index.js (where I create the Gameview). the stepDelta method is called. the problem seem to be in the physics, I'm have something wrong but I don't know what. if I change the restitution of the "Physics.body" almost work.

I create a repository in bitbucket with all the code. here is the link. thanks

https://bitbucket.org/coud/platino-hello-world
My code don't have bugs.. just random and erratic behaviour..

johngould

Hey, just downloaded your code and I'm looking at it now.  I'll let you know if I can find an answer for you on this.

--John  :)

Couds

Hey, I just figure out what was wrong.. I create a behaviour and apply it to the runner body.

Physics.behavior('runner-constraints', function(parent) {
                var defaults = {
                    vel : {
                        x : 0,
                        y : 0
                    }
                };
                return {
                    init : function(opts) {
                        parent.init.call(this, opts);
                        this.options.defaults(defaults);
                        this.options(opts);

                        this._vel = Physics.vector();
                        this.setVelocity(this.options.vel);
                        delete this.options.vel;
                    },
                    setVelocity : function(vel) {
                        this._vel.clone(vel);
                        return this;
                    },
                    behave : function(data) {
                        var bodies = this.getTargets();
                        for (var i = bodies.length - 1; i >= 0; i--) {
                            bodies.state.angular.pos = -0;
                            bodies.accelerate(this._vel);
                        };
                    }
                };
            });

var run = Physics.behavior('runner-constraints', {
                vel : {
                    x : 0.0001,
                    y : 0
                }
            }).applyTo([runner]);

Thanks anyway. if you find another way port it too. =D
My code don't have bugs.. just random and erratic behaviour..

johngould

Nice, you beat me to it!  :D

I'm still getting the hang of PhysicsJS myself - it's a bit different from what I'm used to but very cool when you figure it out.  Thanks for posting that code!

Couds

September 14, 2015, 01:47:49 am #6 Last Edit: September 14, 2015, 02:29:21 am by Couds
me too Im starting with PhysicsJS my self. but is hard to find tutorials of the engine. Now im fighting with the camera :/ don't want to move.

  var transform_camera = platino.createTransform();
            transform_camera.duration = 1000;
            transform_camera.easing = platino.ANIMATION_CURVE_BACK_OUT;
            transform_camera.lookAt_eyeX = SOME_VALUE;
            game.moveCamera(transform_camera);

and nothing happen. I put that code inside a touchstart event. the event is fired but the camera doesn't move :S

-------------------------------

Edit. seem that the camera problem was that I didn't set to TRUE the game.usePerspective;
My code don't have bugs.. just random and erratic behaviour..

johngould

September 14, 2015, 02:38:24 am #7 Last Edit: September 14, 2015, 02:40:59 am by johngould
Okay, so, you've hit on an EXCELLENT reason why we need to get our release notes done on Platino 3!  (Hint, hint, Peach and Joseph!)

One of the big changes we made was to set the default perspective of the game view to orthographic mode.  Someone will have to correct me if I'm wrong, but I believe in orthographic mode, the camera can't be moved.  So typically you would move the sprites and background and stuff around instead of moving the camera.

However, if you do need to move the camera around a scene, which is perfectly valid, just put this in your index.js file:

Code Select
game.usePerspective = true;

That will magically enable the camera movement you're trying to do!  We did add that to our camera sample, I just noticed here: https://platino.io/sample-code/, so I can confirm that that works.  Just be careful about moving around in the Z direction - that can result in some odd behavior since you're dealing with a seemingly 3D camera in a 2D world.  It's not a bug or anything, just not very intuitive behavior.  But as long as you stick to X and Y, you should be good.

--John  :-)


Edit:  Dang, man, you beat me to the punch again!  :P

Couds

Hello.

I fix that. I update the new code. but When fixing the camera position to the runner position sometimes seem very laggy. can you look at the code?

Thanks
My code don't have bugs.. just random and erratic behaviour..

Go Up