00:00
00:00
Newgrounds Background Image Theme

Grh96 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Smoot moving along border AS3

576 Views | 6 Replies
New Topic Respond to this Topic

Smoot moving along border AS3 2014-03-03 18:18:00


Here is the current program. Click and hold to guide character.

After figuring out stuff with the mouse over the past couple days, I finally have the character moving in an acceptable way. When you click and hold the mouse it follows the mouse around. On release, it moves to the point that the mouse was last held at.

What I've got going on now is that while the character's hitTestPoint is touching the land portion of the movie clip he can move, but when he is no longer touching the land, all movements are cancelled.

The problem I have now is that I can't ride along the edges in order to achieve a really smooth movement. I want him to stop from going past the edge of the cliff, but I would still like to be able to ride those edges without it getting stuck on them. He can still move away from the edges fine, but he can't move on them.

I've tried a few things like saving the last two positions in an array and relocating him to the former position, but that caused the same result. I figured it would make it so he's never really on the edge and could still move, but it didn't quite work that way..

If anyone knows about what I'm trying to accomplish with this and has any ideas, I'm all ears. I tried to Google this, but I really couldn't figure out what to ask. Nothing came up. Thanks in advance!

Response to Smoot moving along border AS3 2014-03-03 18:25:58


Take a look at this:
http://www.red3d.com/cwr/steer/

Add some probes to your character to let it sense its environment.

Response to Smoot moving along border AS3 2014-03-03 19:10:22


At 3/3/14 06:25 PM, milchreis wrote: Take a look at this:
http://www.red3d.com/cwr/steer/

Add some probes to your character to let it sense its environment.

This looks like a pretty cool resource. As soon as I update my Java, I'll get more into it.

When you say probes, you mean something like 8 objects around the center of the character that when one or more of them is no longer touching the land, the character can no longer move in that direction?

Response to Smoot moving along border AS3 2014-03-03 20:36:43


At 3/3/14 06:18 PM, Barzona wrote: I've tried a few things like saving the last two positions in an array and relocating him to the former position, but that caused the same result. I figured it would make it so he's never really on the edge and could still move, but it didn't quite work that way..

What you need is pretty much a projection of the movement vector onto the edge.
The problem here is that you don't know where exactly the edge is.

An easy workaround would be to step in x and y direction seperately and check if the current position is valid.
If it is invalid, just undo the last x/y step.
To make this more accurate you may initially divide the movement vector by z and repeat this process z times.

I'm pretty sure there are a lot better "solutions" to this, but I think it should work. (never tested it)

Response to Smoot moving along border AS3 2014-03-03 20:46:46


At 3/3/14 08:36 PM, Etherblood wrote: To make this more accurate

Sry, shouln't have used the word "accurate" here, as this isn't even trying to approximate the orginal solution.
It will look better, but I don't know if it will look good. There are still ways to improve it though.

Response to Smoot moving along border AS3 2014-03-06 17:03:10


At 3/3/14 06:25 PM, milchreis wrote: Take a look at this:
http://www.red3d.com/cwr/steer/

Add some probes to your character to let it sense its environment.

Hey Milchreis, I'm going with your idea of using sensors:

Old movement without sensors.

New movement with sensors.

I still have the character's hitTest active since the sensors slip up sometimes, but it's still a lot smoother. Also, it looks like narrow paths might not be an option. It still gets caught pretty easily in them.

I'm still not sure why the sensors stretch a bit when you pull the character against the edge. They are always following the same x,y positions based on the character's x,y position, so I don't get what's happening. Need to look into it.

Thanks a bunch!

Response to Smoot moving along border AS3 2014-03-10 21:43:26


At 3/6/14 05:03 PM, Barzona wrote: Hey Milchreis, I'm going with your idea of using sensors:

Old movement without sensors.

New movement with sensors.

Nice execution! Game looks cool too.