A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: AS2 Uphill issues

  1. #1
    Member
    Join Date
    Jan 2008
    Posts
    37

    [Solved] AS2 Uphill issues

    As the title says, I have an object moving downhil just fine but instead of moving uphill it will move through the hill.

    How do I make it move along the uphill slope?

    Code:
    onClipEvent (load) {
    	grav = 0;
    	spd = 1;
    }
    onClipEvent (enterFrame) {
    	if (_root.ground.hitTest(this._x, this._y, true)) {
    		grav = 0;
    		this._x += spd;
    	} else {
    		
    		grav += 0.3;
    		if (grav>5) {
    			grav = 5;
    		}
    	}
    	this._y += grav;
    }
    Edit: So it wont let me upload an attachment so ima try this
    -O-----O <--- there are 2 balls here, gravity makes them fall hitting the downslope.
    \........../ They slide down normally and move to the other side.
    \\____ // Where the Uphill for each begins. They will pass through the uphill like it was a flat surface. I hope this helps explain what i mean.
    If not please ask for more description.
    Last edited by Degraiver; 01-03-2010 at 08:00 PM. Reason: wont let me upload an attachment.

  2. #2
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    You need to know the slope of the ground it is traveling on. so it can know what direction to move. Right now, you have nothing to tell it to go up EVER.
    Z¡µµ¥ D££

    Soup In A Box

  3. #3
    Member
    Join Date
    Jan 2008
    Posts
    37
    Oh? I thought:
    PHP Code:
     if (_root.ground.hitTest(this._xthis._ytrue)) { 
    tells the object its borders.
    So how do I tell the object its slope?

  4. #4
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    You need to keep track of the slope of the ground at all locations. Physics like this takes lots of calculations.
    Z¡µµ¥ D££

    Soup In A Box

  5. #5
    Member
    Join Date
    Jan 2008
    Posts
    37
    =D no uphill coding for me. Thanks i dont wanna spend too much time on this.

  6. #6
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    Just wondering...what were you trying to do with this? I may be able to write a simple program for you to look at, just for future reference.
    Z¡µµ¥ D££

    Soup In A Box

  7. #7
    Member
    Join Date
    Jan 2008
    Posts
    37
    Well I wanted monsters to spawn at the top of a mountain, and I wanted the hero to run up the hill to fight the monsters, and Vica versa.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center