PDA

View Full Version : How do I make an entity face a certain direction?



Jeral
07-03-2008, 12:11 AM
trying to figure this out so my charachter isn't always facing up, ive tried a few things but nothing works.

what i want to do is have it so that if you push a directional key, the guy faces that direction.

Seth
07-13-2008, 03:53 AM
Well, it kinds of depends on your setup, if you are using a BrainManager with a "StandardBase", it's very easy.

Just set the direction like this:


this:SetFacing(C_FACING_LEFT);

(Or use SetFacingTarget() if you want the character to actually rotate/turn towards the direction instead of instantly change)

And if you have a visual profile setup, it will automatically use the correct animation for the active direction.

Or, if you're doing things in vector math and don't want to mess with the direction constants, you can do it like this:


this:SetFacing(VectorToFacing(Vector2(0,1)))

(0,1 means "down" in a unit vector, 0 on the x axis, and 1 on the Y axis)

If you are not using a StandardBase brain (or no brain, that's ok too), but still want the ease of use of visual profiles, manually set things every time there is a change like this:


this:SetVisualState(C_VISUAL_STATE_IDLE);
this:SetFacing(C_FACING_LEFT);
this:SetSpriteByVisualStateAndFacing();

Adde
12-14-2008, 07:44 PM
but if i want it to turn a bit left from the angle it already has, how do i do that?
and if i want it to fly a bit forward from the way its pointing, how do i do that?