Object Rotation

Started by mrofa, January 28, 2015, 07:54:41 AM

Previous topic - Next topic

mrofa

I got a 2x2 object which i want to rotate by the center, and i meant object not a texture.
My problem is that it anchors on lower left square , so rotation essentialy change object entire position also.
So do any one got any idea how to do it so that object do go to other squares ?
All i do is clutter all around.

Rikiki

I am not sure if I really understood your question mrofa but something like this may work to compensate the position offset:

// Treatment on rotation event.
            if (this.Rotation == IntRot.north)
            {
                // Nothing to do.
            }
            else if (this.Rotation == IntRot.east)
            {
                this.Position += new IntVec3(0, 0, 1);
            }
            else if (this.Rotation == IntRot.south)
            {
                this.Position += new IntVec3(1, 0, 1);
            }
            else
            {
                this.Position += new IntVec3(1, 0, 0);
            }

mrofa

All i do is clutter all around.

Rikiki

Can you post some screenshots of your problem and what you want please?
It will be easier to help you. :)

mrofa

https://www.sendspace.com/file/oj07yy
Spawn "boxed lept" with from dev menu and try to use rotation button, then you will see the problem :D
All i do is clutter all around.

Rikiki

Wouhou! Not tested yet but I already like the deployment animation! ::)
I will play with it debug it tonight. ;D

Haplo

I had a bit time and looked through your code.
Your idea with the change of the position while turning was good. You just didn't use the right values. The box need to turn on the same spot, so the position must wander: first one step to the top, then to the right, then to the south, then back to the left and so on. Like a dance ;)


        private void RotateBox()
        {
            //Log.Error("old Rotation: " + Rotation.ToString());

            if(this.Rotation ==IntRot.north)
            {
    this.Position += new IntVec3(0, 0, 1);
                this.Rotation = IntRot.east;
            }
            else if (this.Rotation == IntRot.east)
            {
                this.Position += new IntVec3(1, 0, 0);
                this.Rotation = IntRot.south;
               
            }
            else if (this.Rotation == IntRot.south)
            {
                this.Position += new IntVec3(0, 0, -1);
                this.Rotation = IntRot.west;
               
            }
            else if (this.Rotation == IntRot.west)
            {
                this.Position += new IntVec3(-1, 0, 0);
                this.Rotation = IntRot.north;
               
            }
                       
            Find.MapDrawer.MapChanged(this.Position, MapChangeType.Things);
        }

Rikiki

Haplo's first! :D
Nice to see I was looking in the right direction anyway.

mrofa

#8
Did try it like that :D
When rikkiki posted it, but it seems that i didnt add the one for the north one and it did stop all the rest :D
Thanks alot both off you :D
Now to the hardest part of balancing this bad boy xD
All i do is clutter all around.