XNA Creators Club Online
Page 1 of 1 (8 items)
Sort Posts: Previous Next

Need to add Drag Feel to Rotation

Last post 10/10/2009 11:36 AM by MrSoundless. 7 replies.
  • 10/9/2009 9:17 PM

    Need to add Drag Feel to Rotation

    I need to add a drag feel to my rotation. Meaning, when I rotate my player using the Left Thumbstick, it don't want it to be instant. I want it to like slowly go towards that direction... How would I go about doing that?

    Here is what I have so far:

                    Vector2 stick = gamePad.ThumbSticks.Left; 
                    stick.Normalize(); 
                    if ((stick.X >= 0 || stick.X <= 0) || (stick.Y >= 0 || stick.Y <= 0)) 
                    { 
                        Player.Rotation = (float)Math.Acos(stick.Y); 
                        if (stick.X < 0.0f) 
                            Player.Rotation = -Player.Rotation; 
     
                    } 

  • 10/9/2009 10:29 PM In reply to

    Re: Need to add Drag Feel to Rotation

    I could be wrong but I believe that if-statement will always return true..

    To answer your question: what about doing something simple as 



    float maxRotSpeed = 2.0f

    if (rotSpeed < maxRotSpeed ) //max rotation speed?????
    rotSpeed *= 1.3f; //use higher value to speed up faster
    else if (rotSpeed > maxRotSpeed )
    rotSpeed = maxRotSpeed ;


    it's late here so I could be wrong (let's hope I'm not :P)
  • 10/9/2009 10:56 PM In reply to

    Re: Need to add Drag Feel to Rotation

    Hold a variable for the rotation speed and increase it with the thumbstick input:
    float rotSpeed = 0.0f; 
     
    //blah blah blah 
    rotSpeed += (float)(Math.Acos(stcik.Y)*.1f); 
     
    Player.Rotation -= rotSpeed; 
     
    rotSpeed *= .99f; 
    You'll need to adjust for max and min speed, but you get the idea.
    "Software is never finished, it is in varying states of 'less broken'" because "If it ain't broke, it doesn't have enough features yet"

    In Playtest: Avatar Land | The MANLY Game for MANLY Men

    The signature that was too big for the 512 char limit
  • 10/9/2009 11:35 PM In reply to

    Re: Need to add Drag Feel to Rotation

    Hmm, Maybe I didn't make my self clear enough; let me show you a video on the type of movement I wish to achieve.

    http://www.youtube.com/watch?v=g_7AKnkBcso

    This video is of Geometry Wars 2, the movement is exactly like I want to achieve. Instead of the Player Sprite instant turning to the position of the Thumbstick, I like it to slowly to the position of the Thumbstick.

    With the following code:

                    Vector2 stick = gamePad.ThumbSticks.Left; 
                    stick.Normalize(); 
                    if ((stick.X >= 0 || stick.X <= 0) || (stick.Y >= 0 || stick.Y <= 0)) 
                    { 
                        float rotSpeed = 0.0f; 
                        rotSpeed += (float)(Math.Acos(stick.Y) * .05f); 
                        Player.Rotation += rotSpeed; 
                        rotSpeed *= .99f; 
     
                    } 

    What this did was just continuously rotate the object without stopping at the position of the thumbstick.
  • 10/9/2009 11:58 PM In reply to

    Re: Need to add Drag Feel to Rotation

    Ah that's more clear then your first post :P

    I believe this should work:
    - You need a static rotation speed.
    - Calculate the rotaiton of your thumbstick
    - Check if it would be shorter to rotate your ship left or right to reach the rotation of your thumbstick
    - Add/Substract the rotation speed dependant of which side you're rotating.
    - If the ship rotation passes the thumbstick rotation simply assign the thumbstick rotation to the ship rotation.


    P.s.

    Your if statement still doesn't feel right.. I'll explain:

    if ((stick.X >= 0 || stick.X <= 0) || (stick.Y >= 0 || stick.Y <= 0))

    you're checking if stick.X is higher or equal to 0 OR if stick.X is lower or equal to 0. This actually means you're checking if stick.X has ANY value, which it will always have. You do the same for stick.Y

    soo since stick.X will have a value as long as it exists, this statement will always return true.
  • 10/10/2009 12:10 AM In reply to

    Re: Need to add Drag Feel to Rotation

    Thank You. I figured it would be something like that. I'll post back with my results later.
  • 10/10/2009 11:23 AM In reply to

    Re: Need to add Drag Feel to Rotation

    First, rotSpeed would need to be outside the main loop so the speed can accumulate. This was intended to add some "acceleration" to the turning, but it won't do what you want with GeoWars-style movement.

    To get that style of movement, you need to hold the current rotation, and the destination rotation. You then decide which way is shorter to turn, and add to or decrease the current rotation value until it is equal to the destination rotation value. This way it will slowly rotate towards the destination rotation.
    float curRot; 
    float destRot; 
     
    void Update() 
        if(moving) 
        { 
            destRot = (float)Math.Acos(stick.Y); 
        } 
     
        if(Left_Is_Shorter) 
        { 
            curRot -= speed; 
            if(curRot < destRot) 
                curRot = destRot; 
        } 
        else 
        { 
            curRot += speed; 
            if(curRot > destRot) 
                curRot = destRot; 
        } 
     

    "Software is never finished, it is in varying states of 'less broken'" because "If it ain't broke, it doesn't have enough features yet"

    In Playtest: Avatar Land | The MANLY Game for MANLY Men

    The signature that was too big for the 512 char limit
  • 10/10/2009 11:36 AM In reply to

    Re: Need to add Drag Feel to Rotation

    to calculate which side is shorter you could do something like this

    float leftDistance = curRot + MathHelper.TwoPi - destRot; 
    float rightDistance = destRot - curRot; 
     
    if (leftDistance < rightDistance) 
        //left is shorter, rotate left 
    else 
        //rotate right 

Page 1 of 1 (8 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG