Author Topic: moving a block help  (Read 2621 times)

flabby_fabby

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
moving a block help
« on: Thu, Dec 1, 2011 »
When the player pushes the block it doesn't stop moving. How would I add friction?


Code: [Select]
package 
{
import org.flixel.*;

public class block extends FlxSprite
{
[Embed(source = '../assets/block_img.png')] private var blockPNG:Class;

public function block(X:Number,Y:Number)
{
super(X * 8, Y * 8, blockPNG);
acceleration.y = 400;
}

}

}
« Last Edit: Thu, Dec 1, 2011 by flabby_fabby »
[ ^___^ ]

flabby_fabby

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: moving a block help
« Reply #1 on: Thu, Dec 1, 2011 »
I found that i can use Drag. WOOP WOOP!!  ;)

The only problem I have now is when the player is on the edge of the block and changes direction, the block also moves.

Any ideas???
[ ^___^ ]

test84

  • Key Contributor
  • *****
  • Posts: 1328
  • Karma: +0/-0
  • ت
    • View Profile
    • My personal site.
Re: moving a block help
« Reply #2 on: Thu, Dec 1, 2011 »
I think we need to see more code in order to reply to that one.
blog, twitter, Check out my award winning game, Rot Gut:

flabby_fabby

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: moving a block help
« Reply #3 on: Thu, Dec 1, 2011 »
block.as

Code: [Select]
package   
{
   import org.flixel.*;
   import org.flixel.plugin.photonstorm.*;
   
   public class block extends FlxSprite
   {
      [Embed(source = '../assets/block_img.png')] private var blockPNG:Class;
     
      public function block(X:Number,Y:Number)
      {
         super(X * 8, Y * 8, blockPNG);
         immovable = false;
         moves = true;
         acceleration.y = 400;
         drag = new FlxPoint(100, 0);
      }
   }

}

PlayStase.as update();

Code: [Select]
override public function update():void
      {
         super.update();
         
         FlxG.collide(player, level);
         FlxG.collide(level, level);
      }

<a href="http://www.swfcabin.com/swf-files/1322757822.swf" target="_blank" rel="noopener noreferrer" class="bbc_link bbc_flash_disabled new_win">http://www.swfcabin.com/swf-files/1322757822.swf</a>


(press up to jump)
[ ^___^ ]

test84

  • Key Contributor
  • *****
  • Posts: 1328
  • Karma: +0/-0
  • ت
    • View Profile
    • My personal site.
Re: moving a block help
« Reply #4 on: Thu, Dec 1, 2011 »
I can't see the actual swf in action, due to my Internet problem but I can safely assume that 1) your problem is not in those codes that you just posted and probably is somewhere at your player's update and 2) Why you collide(level, level) ?
blog, twitter, Check out my award winning game, Rot Gut:

camasthecat

  • Contributor
  • ****
  • Posts: 461
  • Karma: +0/-0
  • WOW! 400+ Posts!? Jeez! Do I have a life!?!?
    • View Profile
    • My site for thermalJS, an HTML5/Javascript engine kinda-like flixel:
Re: moving a block help
« Reply #5 on: Thu, Dec 1, 2011 »
I think it has something to do with flixel's code that pushes an object out to collide...

Alextfish

  • Active Member
  • ***
  • Posts: 174
  • Karma: +0/-0
    • View Profile
Re: moving a block help
« Reply #6 on: Fri, Dec 2, 2011 »
I had a little play with the SWF and can't see the problem.

Could you describe precisely what's the behaviour you're seeing that's undesirable?

I.e. 1) What are the circumstances when it happens? Where is the player, where is the block, where is the platform? 2) What precisely happens? 3) What precisely would you want to happen instead?

flabby_fabby

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: moving a block help
« Reply #7 on: Fri, Dec 2, 2011 »
When the hero is over hanging over the block and you walk into the block, the block moves.

I want the hero to walk over it without it affecting the block.

So I only want the block to move if ( hero._y + hero._height > block._y )



Hopefully this picture explains it more. The red outline is the offset of the image for collision.



Also, I did a collide test with level to level because the blocks fall through the platform if I don't.

Is there a better way to do this?
[ ^___^ ]

wg/funstorm

  • Global Moderator
  • Key Contributor
  • *****
  • Posts: 596
  • Karma: +0/-0
    • View Profile
    • Funstorm
Re: moving a block help
« Reply #8 on: Sun, Dec 4, 2011 »
Can't see the picture "Your client does not have permission to get URL /-pTzMMQFW1Jrx848b4koY92giGsBdJ1SGi-xtjtxbCnnWL0EyAsnEIU4PcRCeFSOQ7kpWPrARcrBC1WlDrB2mufKYpR5y6OsVHU=w1024 from this server."

flabby_fabby

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: moving a block help
« Reply #9 on: Sun, Dec 4, 2011 »
sorry about that. here's the image...

[ ^___^ ]

OldmanBiles

  • Member
  • **
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: moving a block help
« Reply #10 on: Mon, Dec 5, 2011 »
I can't see the swf above. So you're saying that you don't want the block to move when the player walks over it, but you do want it to move if he walks into it?

If so, can't you just set the immovable tag inside your flxsprite when the player is colliding with the top of the box?

Kytin

  • Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: moving a block help
« Reply #11 on: Mon, Dec 5, 2011 »
So I only want the block to move if ( hero._y + hero._height > block._y )

Shouldn't that be if ( hero._y + hero._height < block._y )?
The way you have it, the block only moves when the player is above it.

Also, I did a collide test with level to level because the blocks fall through the platform if I don't.

Is there a better way to do this?

Create a separate group for the blocks and collide that group against the level. This also has the advanage that you can collide them with the player separately, using a different function if you choose.
I have seen the future. You will not.

noFunk

  • Member
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Re: moving a block help
« Reply #12 on: Tue, Dec 6, 2011 »
I had a similar problem, take a look at this post it really helped me out
http://forums.flixel.org/index.php/topic,4479.msg27640.html#msg27640