• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
FantasyVI

player look at the mouse, not as easy as it sounds

4 posts in this topic

hay guys

can someone tell me how can i make the player look at the mouse like in Alien shooter ? here take a look at this video.

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

i'm Using SFML and c++
0

Share this post


Link to post
Share on other sites
Reverse project the on-screen mouse coordinates into world coordinates to calculate the location on the ground plane of the mouse, subtract the player's location from this mouse position to calculate a vector, normalize that vector to unit length and calculate a rotation matrix around the Up axis that will orient the player to face along that vector. This works if your characters are 3D models. If they are 2D pre-rendered, then instead of calculating a rotation matrix, you would select the appropriate facing-direction animation from the set of facing directions.
0

Share this post


Link to post
Share on other sites
[quote name='JTippetts' timestamp='1311856691' post='4841549']
Reverse project the on-screen mouse coordinates into world coordinates to calculate the location on the ground plane of the mouse, subtract the player's location from this mouse position to calculate a vector, normalize that vector to unit length and calculate a rotation matrix around the Up axis that will orient the player to face along that vector. This works if your characters are 3D models. If they are 2D pre-rendered, then instead of calculating a rotation matrix, you would select the appropriate facing-direction animation from the set of facing directions.
[/quote]

thank you :)
0

Share this post


Link to post
Share on other sites
you can also do the following.

you get the x and y coordinate from the mouse..

than u divide the screen into 4 areas and let the player be 0/0 as the midpoint


[code]
|
|
|
|
--------------P--------------
|
|
|
|

[/code]

you look now in which area the mouse is and than u create a right-angled triangle.

the vector from the player to the mouse is the hypotenuse. from now you can calculate the alpha or beta radiant and use this to rotate your caracter.

I used this technic 2 weeks ago in a game i wrote which will soon be available on my blog (with source code).. [url="http://howtomakeitinamsterdam.wordpress.com/"]http://howtomakeitin....wordpress.com/[/url]

heres the source code.. ( i know, most of the variables are useless and it could be written shorter, .. i dont know what i did, it was 5am s.th. :-)

[code]

void CObject::rotate(unsigned int pointx, unsigned int pointy, int w, int h)
{
unsigned int midx = this->x + w/2;
unsigned int midy = this->y + h/2;

double squarea;
double squareb;
double root;
double angleplus;

// create triangle
double b; // ankathete
double a; // gegenkathete
double c; // hypothenuse c = sqrt(a² + b²)

// in which area is pointx, pointy;
if (pointx > midx && pointy < midy) // viereck oben rechts
{
b = pointx - midx;
a = midy - pointy;
this->angle = 270; // stellt object auf 0 grad

squarea = a*a;
squareb = b*b;

root = squarea+squareb;

c = sqrt(root); // hypothenuse berechnet

angleplus = asin(b/c)* 180.0 / M_PI;

this->angle=this->angle+angleplus; // addiert den winkel
}
else if (pointx > midx && pointy > midy) // viereck unten rechts // gut
{
b = pointx - midx;
a = pointy - midy;
this->angle = 0;
squarea = a*a;
squareb = b*b;

root = squarea+squareb;

c = sqrt(root); // hypothenuse berechnet

angleplus = acos(b/c)* 180.0 / M_PI;

this->angle=this->angle+angleplus; // addiert den winkel
}
else if (pointx < midx && pointy < midy) // viereck oben links // gut
{
b = midx - pointx;
a = midy - pointy;
this->angle = 180;
squarea = a*a;
squareb = b*b;

root = squarea+squareb;

c = sqrt(root); // hypothenuse berechnet

angleplus = acos(b/c)* 180.0 / M_PI;

this->angle=this->angle+angleplus; // addiert den winkel

}
else if (pointx < midx && pointy > midy) // viereck unten links
{
b = midx - pointx;
a = pointy - midy;
this->angle = 90;
squarea = a*a;
squareb = b*b;

root = squarea+squareb;

c = sqrt(root); // hypothenuse berechnet

angleplus = asin(b/c)* 180.0 / M_PI;

this->angle=this->angle+angleplus; // addiert den winkel
}
}
[/code]
1

Share this post


Link to post
Share on other sites
[quote name='FlyingDutchman' timestamp='1312230052' post='4843251']
you can also do the following.

you get the x and y coordinate from the mouse..

than u divide the screen into 4 areas and let the player be 0/0 as the midpoint[/quote]

Alternatively, you just use atan2.


1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0