I'm using a debug player version and when i click on "play" btn, this alert is shown:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at kniferider.view::DrawingView/onMainMenuStateChange()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at com.alisdairmills.binding::ChangeWatcher$/onPropertyChange()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.alisdairmills.event::Bindable/broadcastChange()
at kniferider.model::NavigationModel/set mainMenuState()
at kniferider.command::MainMenuCommand/execute()
at com.alisdairmills.control::ApplicationController/executeCommand()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at kniferider.view::MainMenuView/onNavigationItemPress()
Can I ask how you made the guy walk? Did you turn him into a box or something and then just play a walking animation?
Sorry for taking so long to reply- I spotted the bug myself but only got time to go through the interface dev's code and fix it the other day. Cheers for that though 🙂
As for walking: God knows if this is the intelligent way to do it, but it works for the most part...
The character has two representations. When he's walking, he's essentially a man on a unicycle. An animation and a man-shaped rectangle are attached to a body def with a guide circle shape attached, acting as his feet. This body def then gets angular velocity applied to it whenever he's on a surface, which makes him walk forward.
If the linear velocity of that circle drops below a certain threshold, I assume the slope is too steep to walk up or he's blocked in that direction, and so he'll turn round and apply angular velocity in the other direction. So long as the circle is in contact with a surface- I'm setting the userdata flag on the objects to indicate this- he'll keep walking.
The second representation is the rag doll. When the hit-box on top of the guide circle is hit by an object with sufficient force, or the guide circle isn't on a surface for a set amount of time, the ragdoll is swapped in. After that, provided he is in contact with *something* for more than five seconds or so he tries to get up. Once he's clear of whatever he's lying on, there's a quick test with the guide circle to see if it can touch a surface. If yes, then he can go back to the walking representation.
Unfortunately time constraints made all this a little hacky. If anyone's got any better ideas of how to go about making characters walk, I'd love to hear them.
Please excuse anthropomorphism 🙂
Genius, I love the unicycle idea. I was looking for a way of causing character motion via friction rather than by adding arbitrary forces, but short of modifying the engine, I couldn't find a way of having fiction behave as if you were at an offset velocity, while actually moving in another direction.
Are you setting the unicycles angular velocity, or applying torque? As far as I could tell, he walks slower up slopes than down, which isn't consistent with a fixed rotation speed.
Setting the angular velocity still makes sense if you consider the effects of gravity and friction and you want a more or less constant pace. Set the torque and you'll start accelerating when going downhill; set the angular velocity and you'll just be reliant on friction (in this case set really, really high given that our chap isn't on rollerskates) and gravity, which keeps him stuck to the floor.
I'm sure there's a ton of other ways to address this though.
That's a good idea. I've been using a rectangle with a sort of rounded bottom to help him move up slopes, and applying an impulse to the center of his body. It works fairly well except for a few kinks, and allows him to change direction in mid-air (good for games). Thanks for sharing!