[SOLVED: Problem wasn't about collideLine] What is the problem? CollideLine


(Bora Kasap) #1

I’m using this code to give damage to the player while player colliding a line, but it doesn’t work properly, it only works when the line come closer to horizontal position. My player’s hitbox size is 28x17

override public function update():void
	{
		var p:Player = Player(FP.world.collideLine("player", this.source.x, this.source.y, this.target.x, this.target.y));
		if (p != null) GLOBALS.armor -= 5;
	}

(azrafe7) #2

Well, too many pieces of the puzzle are missing to give a suggestion here. Can you please share more of your code?

  • the update() is within the Player? If not, to which class it belongs?
  • what are source and target and where are they set?
  • are the involved Entities all added correctly?

A few tips (I know I’m too much into lists lately :smirk:) …

  • in many cases the Console can give a great hand in solving things like this (you can try enabling it and see if your entities hitboxes are positioned as you expect)
  • you could / should also take advantage of FlashDevelop, compile in Debug mode and set some breakpoints to see what values your variables assume at a given time (assuming you’re on Windows and developing with it)
  • another very useful trick is to use the Draw class to draw things in an overridden render() method.

In your case you could try this:

override public function render():void {
    super.render();

    Draw.line(this.source.x, this.source.y, this.target.x, this.target.y);
}

(don’t know if you must account for camera position in there, 'cause I don’t know yet what source and target are).

But if you can post your code we could surely have a better idea of what could be wrong in it and hopefully be able to come up with a solution.


(Bora Kasap) #3

I’m using this lines inside this class: Lightning Effect Class [Code Fixed & Preview Video Added]

Source and target are entities and my player’s collision works with everything without that line. Also i don’t use collideLine without that line.

Sorry for i can’t share all code because of i’m at work now. Player’s movement speed is about 100*FP.elapsed for this situation and i’m using 60fps.


(azrafe7) #4

I’ve tried your code and it works: LightningTest

Rethinking about it… probably the player goes too fast and just jumps the line, resulting in no collision. If this is the case (you can easily test it decreasing the speed of your player), you can try to work around that by using two parallel lines to check for collision.

Also… for an interesting take on lightnings: http://drilian.com/2009/02/25/lightning-bolts/


(Bora Kasap) #5

Thanks for your “also” ::slight_smile:

Also, it is not about player’s speed, because i’m waiting on the line and nothing happens. My source and target are moving entities, so they are moving and the lightning’s direction changing continuously, my entities making a circular movement and lightning is rotating around them, but lightning’s collision doesn’t work unless it’s rotation comes closer to horizontal position.

I’m gonna check my code again… I’m so curious about what’s my fault :smiley:


(Bora Kasap) #7

Oh man, it wasn’t about collide line :S :S it was about my player’s armor indicator, i was forgot to update indicator when it takes lightning damage so i can’t see it is taking damage, i just see it is dying before some time, so i was thought it was about lightning direction :smiley: i’m sorry and thanks for help :))))))


(azrafe7) #8

Ha! Glad it’s solved, anyway!

But next time just setting a breakpoint to step through code and actually check what values p assumes could save you some unneeded headache. :smirk: