Tutorial: Attach camera to a bone



Users browsing this forum: No registered users and 3 guests

Next topic
Previous topic
Post new topic Reply to topic  NeoAxis Forum Index » General » Tutorials and Articles from Community
Search for:
Author Message
Unlimited License
Unlimited License
User avatar

Joined: Mon Jan 05, 2009
Posts: 791
Location: Belgrade
PostPosted: Mon Mar 09, 2009 8:34 pm Post subject: Tutorial: Attach camera to a bone
Bottom of Page Back to top
Have you ever wanted to have your camera move and wave along with your character, or make peeking around the corner with just an animation, or realistic recoiling from your oponents? Well here is a quick way to do it:

1. Open the Game project.
2. Find and open ActionGameWindow.cs
3. Find these lines:
Code: Select all   Expand view
else
{
    position = unit.GetInterpolatedPosition();
    position += unit.Type.FPSCameraOffset * unit.GetInterpolatedRotation();
}

4. Then replace them with:
Code: Select all   Expand view
else
{
    Vec3 pos = Vec3.Zero;
    Quat rot = Quat.Identity;
    Vec3 scl = Vec3.Zero;
    bool hasHead = false;

    foreach(MapObjectAttachedObject obj in unit.AttachedObjects)
    {
        if (obj as MapObjectAttachedHelper == null)
            continue;

        if (obj.Alias == "Head")
        {
            obj.GetGlobalInterpolatedTransform(out pos, out rot, out scl);
            hasHead = true;
            break;
        }
    }

    if (hasHead)
    {
        position = pos;
        position += unit.Type.FPSCameraOffset * rot;
    }
    else
    {
        position = unit.GetInterpolatedPosition();
        position += unit.Type.FPSCameraOffset * unit.GetInterpolatedRotation();
    }
}


5. Open your Resource Editor and then Rabbit.type (or any of your PlayerCharacter).
6. Add the head bone slot in the mesh:
[URL=http://img13.imageshack.us/my.php?image=tut01.jpg]Image[/URL]

7. Attach helper object:
[URL=http://img82.imageshack.us/my.php?image=tut02.jpg]Image[/URL]

8. Set its scale to 0.1 0.1 0.1 (irrevelant but visualy helps), its alias to Head (this is needed for recognizing), and its bone slot to head (also very important):
[URL=http://img10.imageshack.us/my.php?image=tut03.jpg]Image[/URL]

9. Save, run any level and enjoy!

P.S. Rabbits animation speed (and animation) is very weird (in positive way) as you will see directly from his eyes :)


Last edited by Hell Entertainment on Tue Mar 10, 2009 9:37 am, edited 1 time in total.


_________________
Updated GridPathFindSystem
Smarter AI
Arilienta (Our NA Game)
 
 Profile  
Moderator
Moderator
User avatar

Joined: Wed Nov 28, 2007
Posts: 1508
Location: Vancouver, British Columbia
Country: Canada (ca)
PostPosted: Mon Mar 09, 2009 9:25 pm 
Bottom of Page Back to top
Thanks! :)

This is much simpler than the method we used.

_________________
I'm NOT paid or work for NeoAxis. I only help moderate these boards. My opinions are not the opinions of NeoAxis Group LTD.
 
 Profile  
Unlimited License
Unlimited License
User avatar

Joined: Mon Jan 05, 2009
Posts: 791
Location: Belgrade
PostPosted: Mon Mar 09, 2009 9:47 pm 
Bottom of Page Back to top
Thanks, glad it is of some help :)
Added a link to this thread on the wiki.

EDIT: I saw you added chase radius in Incognito that i wrote on wiki with my old account :)
Now moved it to AI code snippet.

_________________
Updated GridPathFindSystem
Smarter AI
Arilienta (Our NA Game)
 
 Profile  

Joined: Mon Mar 09, 2009
Posts: 40
Location: Mars
PostPosted: Mon Mar 09, 2009 10:38 pm 
Bottom of Page Back to top
Would using this method let the player be able to look down and see the player models legs? Like in the game Mirrors Edge, Left 4 Dead, etc.

_________________
Image

http://www.mirrorversegames.com
 
 Profile  
Unlimited License
Unlimited License
User avatar

Joined: Mon Jan 05, 2009
Posts: 791
Location: Belgrade
PostPosted: Tue Mar 10, 2009 9:35 am 
Bottom of Page Back to top
It is not used for that. Simply enable displaying of characters model, and adjust FPSCameraOffset.

_________________
Updated GridPathFindSystem
Smarter AI
Arilienta (Our NA Game)
 
 Profile  
User avatar

Joined: Sat Nov 15, 2008
Posts: 21
Location: Petrovsk
Country: Russia (ru)
PostPosted: Sat Apr 25, 2009 11:28 am 
Bottom of Page Back to top
Thank you very much!

_________________
consulneoaxis.blogspot.ru
My Turbosquid Models
 
 Profile  
User avatar

Joined: Thu Sep 09, 2010
Posts: 52
Country: Mexico (mx)
PostPosted: Fri Sep 24, 2010 10:30 pm 
Bottom of Page Back to top
Great stuff (y)
can you please explan the code??

_________________
Image
 
 Profile  

Joined: Tue May 13, 2008
Posts: 306
PostPosted: Sun Oct 03, 2010 9:20 am 
Bottom of Page Back to top
Hi .

We used your method for our camera movement in our game but there is 2 problem :

1- your method does not have any thing about camera rotation .

2- when using sky domes (which we use)as you know sky is attached and related to the camera . so when camera moves sky domes moves too !!!

any suggestions ?

 
 Profile  
User avatar

Joined: Thu Sep 09, 2010
Posts: 52
Country: Mexico (mx)
PostPosted: Thu Oct 07, 2010 9:40 pm 
Bottom of Page Back to top
About the camera rotation

Well i've codding a camera rotation for cars which rotates whit the car, i figure out that the camera CANT be rotatet or at least is not possible to set the rotation of the camera so what you need to do is rotate the fordward an up propeties when the camera values are specified, this is done by multipling the fordward * unit.GetInterpolatedRotation()
and
up * unit.GetInterpolatedRotation()
this will rotate the camera, tested!!
im not at home, so letme get into my home and i will upload the exact code

and besides the sky dome i have no freaking idea :P

CYA

_________________
Image
 
 Profile  
User avatar

Joined: Thu Sep 09, 2010
Posts: 52
Country: Mexico (mx)
PostPosted: Fri Oct 22, 2010 1:59 am 
Bottom of Page Back to top
I hope nobody notice im doing double post

Well, im at home and this is code to rotate the camera
Code: Select all   Expand view
else 
{
    Vec3 pos = Vec3.Zero;
    Quat rot = Quat.Identity;
    Vec3 scl = Vec3.Zero;
    bool hasHead = false;

    foreach(MapObjectAttachedObject obj in unit.AttachedObjects)
    {
        if (obj as MapObjectAttachedHelper == null)
            continue;

        if (obj.Alias == "Head")
        {
            obj.GetGlobalInterpolatedTransform(out pos, out rot, out scl);
            hasHead = true;
            break;
        }
    }

    if (hasHead)
    {
        position = pos;
        position += unit.Type.FPSCameraOffset * rot;
        up = Vec3.ZAxis * obj.GetInterpolatedRotation();//set the up setting
        forward *= obj.GetInterpolatedRotation();// set the foward pos whit out moving the intellect lookdir
    }
    else
    {
        position = unit.GetInterpolatedPosition();
        position += unit.Type.FPSCameraOffset * unit.GetInterpolatedRotation();
    }
}


its a simple modification, i only add 2 lines but took a lot of figuring out

_________________
Image
 
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  NeoAxis Forum Index » General » Tutorials and Articles from Community

Jump to:  

Next topic
Previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron

All times are UTC




Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group