NNKL.COM
welcome to my space
X
Search:  
 HOME   Need help with some 'advanced keyboard movement'...
Need help with some 'advanced keyboard movement'...
Published by: cfz 2010-03-16
Welcome to:nnkl.com

  • Hi

    I'm starting a new game where the user
    rides a jetski through the water, dodges
    stuff and shoots enemies along the way
    (based around a 007-style theme).

    What I need is some help coding the movement
    of the jetski (left and right). All I can do is
    this:

    onEnterFrame = function() {
    if (Key.isDown(Key.RIGHT)) {
    jetski._x += 10;
    }
    }
    (and do the same for 'left', of course)

    As you can see its very basic and will
    only make very 'linear' movement. What
    I need is to sort-of 'ease' the motion of
    the jetski. Like 'skidding' a little bit.

    I think it's a mathematical thing...
    Quadratics? :puzzle:

    Please help! :beam:
    World Editor Help [Archive] - Page 183 - The Helper Forums::
    help Warcraft 3 World Editor Mappers with questions from basic to advanced. Im New To the Map Making Need Some Help. I need a Rain of Arrows icon.
    http://www.thehelper.net/forums/archive/index.php?f-42-p-183.html
    HOME

    Thanks in advance.


  • Ah, I see what you're saying - yes, that should work fine, and it sounds like that will give you the naturalistic movement you're looking for.

    Let me know how it works out - post an update here if you can, when you make some progress.

    Steve


  • what i would do is to increment a speed variable, not the position directly, like when right key is pressed increment speed, when left key is pressed decrease the speed (it should be allowed to go negative values so you can move to either side) and on enterframe add the speed value to x and also when no keys are pressed the speed should decay: like speed *= .9

    hope u get the picture


  • true, it probably should be bouncing a lil bit at all times, that actually doesn't look bad at the different perspective. heh.. I never claimed to be a good artists.. my jetski was kinda crap.


  • Looks like it's working well. The link worked fine for me, F4F - maybe it was temporarily down or something?


  • Very cool AP - I added a few elements (the jetskiier is clipart - it's the wrong angle though) just to get the effect. Very neat stuff - though there should probably be a bit of hop/bounce going on all the time, from the effects of the waves, don't you think?

    Steve


  • Hey, i figured I would give this a shot and got WAY more into than I thought I would. Heres what I came up with.
    Buy.com - RCA Gyration GC1205FKM Cordless Air Mouse & Full Keyboard ::
    Shop by Brand | Rebate Center | Need Help Deciding? Movement Detection. Optical. Keyboard/Keypad Operating Distance. 33 ft Wireless. Product Model
    http://www.buy.com/prod/rca-gyration-gc1205fkm-cordless-air-mouse/q/loc/101/201964872.html
    HOME
    QBasic/Advanced Input - Wikibooks, collection of open-content textbooks::
    The memory in the keyboard controller chip (called a buffer) would do just that. constantly has to update the screen to show the movement of the ball.
    http://en.wikibooks.org/wiki/QBasic/Advanced_Input
    HOME


    accelX = jetski._x; // So the jetski starts at the right spot.
    turnSpeed = 1; // the rotation speed of the ski.
    turnThresh = 20; // The max rotation threshold.
    accelSpeed = 5; // The acceleration speed of the jetski
    accelHop = .2; // The acceleration speed of the "bobbing"
    threshY = 5; // The threshold of the "bobbing"
    idleRot = 1; // The "return" speed of the rotation while iddle.
    baseY = jetski._y;

    onEnterFrame = function () {
    if (Key.isDown(Key.RIGHT)) {
    accelX += accelSpeed; // increase X accleration speeed.
    (jetski._y>baseY-threshY) ? accelY += accelHop : accelY -= accelHop; // Bobbing checks
    (jetski._rotation>turnThresh) ? null : rot += turnSpeed; // Turning Checks
    }
    if (Key.isDown(Key.LEFT)) {
    //same as above, but opposite directions.
    accelX -= accelSpeed;
    (jetski._y>baseY-threshY) ? accelY += accelHop : accelY -= accelHop;
    (jetski._rotation<-turnThresh) ? null : rot -= turnSpeed;
    }
    if (!((Key.isDown(Key.RIGHT)) (Key.isDown(Key.LEFT)))) { // Check if there are no keys being pressed
    (jetski._y if (Math.abs(jetski._rotation)<=idleRot) { // ensure there isn't weird "wobbling"
    rot = 0;
    } else {
    (jetski._rotation<0) ? rot += idleRot : null; // rotate right.
    (jetski._rotation>0) ? rot -= idleRot : null; // rotate left.
    }
    }
    jetski._y -= accelY; // bobbing effect.
    jetski._x += (accelX-jetski._x)/14; // accelerate the jetski, divide for sluggish motion.
    jetski._rotation += (rot-jetski._rotation)/4; //rotate the jetski, divide for sluggish motion.
    };
    stop();


    All you need to do is put that on the first frame and make a clip named "jetski." But I would suggest re-writing it and understanding it, and then you can change stuff about it to suit your needs.. for instance you might not want the jetski code on the enterframe of _root.

    Heres the .fla, I added a line to show water level. If anyone has any tips to make the code better, feel free to shout em out. I didn't mess with changing the onEnterFrame from being on the root or the button testing or anything, even though it might be a good idea to do so.


  • YA3,

    I think the best and easist solution is to think of the X position of the jetski as a destination, so that hitting the left and right arrow keys increases a variable called something like xDest - then, the jetski can constantly be checking its own position to see if it's to the left or right of that target destination, and it can move itself accordingly - and, that way, you can add inertia so it moves slowly.

    I created a similar type of motion for the paddle in this Breakout-style game:

    http://www.plasmicstudio.com/bustthrough

    The paddle has a very small amount of inertia (which you can increase or decrease by adjusting one variable) so that its movement is a little slower than the mouse. If you'd like the .fla for this, let me know and I'll provide it.

    Steve


  • wow.

    thanks a lot everyone!

    ive got a pre-pre-alpha version up.
    http://www.myvipcard.com.au/yakub/jetski/jetski1.swf


  • probably, i tried it again and it worked


  • the link didnt work for me!


  • for the "hoping around" of the waves i got an idea:


    onClipEvent (load) {
    waveIntensity = 10;
    degrees = 0;
    speed=10
    }
    onClipEvent (enterFrame) {
    degrees+=speed;
    _y = Math.sin(degrees*(Math.PI/180))*waveIntensity;
    }


    but u have to experiment around with the values to get a realistic effect, and maybe add to degrees the speed of the jetski, so when its going fast it bounces more and when theres no speed at all it doesnt bounce

    by the way ya3 if u are going to use our code a small credit would be nice...





  • Get Smart About Monitoring Virtual Machines
    Microsoft Gets Ex-Streamly Cozy with U.K.'s MediaWave

    You are looking at:nnkl.com's Need help with some 'advanced keyboard movement'..., click nnkl.com to home
  • what limits for warrantless wiretapping
  • aol extends mobile reach with mymobile
  • ctia ground airline cell phone use
  • sap is wooing the blackberry crm crowd
  • fcc nextwave deal to free up spectrum
  • ibm puts soa spin on new db2
  • white house issues spectrum policy proposals
  • mobile ads to kids ftc opens debate
  • verizon snags more spectrum
  • fcc approves spectrum swap
  • the specter of spectrum at ctia
  • sales data new challengers don t bode well for moto
  • motorola s still looking hard for its mojo
  •  
  • wireless broadband said to use wrong spectrum
  • will mobile ads finally get their due
  • nokia s new tablet offers high speed mobility
  • ctia fcc chairman hails openness in wireless industry
  • fcc makes more unlicensed spectrum available
  • wireless enterprises position for spectrum
  • microsoft mobile devices to show banner ads
  • a leaner nortel
  • fcc seeks tv white space spectrum for wi fi
  • a converged gateway to nortel s ims suite
  • vz wireless nextel play hardball over spectrum license
  • ctia a wireless world in sin city
  • wireless goods from ctia
  • tenxc applies spread spectrum smarts
  •  Homepage | Add to favorites | Contact us | Exchange links | LOGIN | Site map | 
    Copyright© 2008 nnkl.com        Site made:CFZ