How to maintain sprite offset when scene object is rotated
Shri

Gio,

 

I have a question regarding maintaining an offset for a sprite when the scene object it is attached to is rotated.

 

For example, if you have a gun attached to say a boat, and the gun is at the boats bow (front).

When you set up the boat object, the gun sprite is added with an offset of for example {x:0, y:-20}.

Now when the scene object is rotaed 180 degrees, the gun is now at the rear of the boat. That is, the offset is constant {0,-20}, and not updated when the scene object rotates

 

I know how to do this manually in the update routine via resetting the offset position based on the sine and cosine of the rotation of the scene object.

 

My question is - is there a parameter I can set on initialization, or some method to call so that the sprite offset remains the same  relative to the scene objects rotation ?

In the above example, the initial offset would be {0,-20}

When the boat is rotated 180 degrees, the offset should now be {0,20}

new x offset = -20 * sin(180) = 0

new y offset = -20 * cos(180) = 20

And the gun still appears at the bow of the boat.

 

As usual, any help you can provide would be appreciated.

 

cheers,

Shri

All 5 Comments
foxcode

Hi Shri, I actually ran into a similar issue programming a game we have not released yet.

 

Turns out wade does not yet have an option for doing this other than manually as you suggested. I talked to Gio about it at the time and he said it is something we will add but I do not know when. Sorry I cannot be more helpful. Your boat game is pretty cool by the way, though as a hard core fps player the controls drove me nuts :p am too used to wasd, nice concept though.

Gio

It's actually a bug in WADE - sprite offsets should be relative to the parent object when it is NOT rotated. When it's rotated, sprite offsets should be rotated automatically by WADE. The current behavior is confusing and should be changed.

 

I have fixed it locally and it will be available in WADE 1.4.1 next week.

 

By the way, there is also wade.vec2.rotate() when you need to manually rotate a vector :)

Shri

Foxcode,

 

Thanks for the feedback - I changed the keyboard controls and now they are wasd (fwd, left, right,  reverse).

 

Gio,

 

I'm glad I'm not the only one who thinks that if your holding something  in front of you, it should still be in front of you when you turn aroundI. I will wait on the the 1.4.1 release.

As an aside, I implemented some steering behavior in pt raid. Any chance that steering or ai routines will be added to the base engine like they are in the iso plugin ?

 

thanks for the quick response

 

cheers,

Shri

Gio

I think they should be behaviors rather than built into the base engine, but we'll have to make it easier to share these behaviors. As you know, we've been working on a system to do that for quite some time :) We're making progress though.

 

One of these days I'll sort out adding your behaviors to the market. We have a couple of our own that we want to share too.

Gio

WADE 1.4.1 released, it contains the rotation bug fix as discussed above:

 

 

BugFix (B121): When rotating a scene object, sprite offsets aren't automatically rotated
Post a reply
Add Attachment
Submit Reply
Login to Reply