• 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.

Setroid

Members
  • Content count

    1
  • Joined

  • Last visited

Community Reputation

103 Neutral

About Setroid

  • Rank
    Newbie
  1. I was programming a game in Unity using C# where the character needs to start sliding, which would change the controls when the slope is too steep. I did a few searches on the web, and I couldn't find a thing. So, I dug out my Calculus book, and looked up min/max points on a multidimension equation, when I realized that the information that I get from the object is a plane, and that I should be using the equation of a plane to solve this problem. Here's what I came up with: // The variables private RaycastHit groundBelow;     // stores the raycast information private Vector3 downwardDirection;  // stores the vector information of the downward slope   // This function sets the downwardDirection to a normalized vector down the slope. // (In Unity the y-axis is the vertcal component) if(Physics.Raycast(transform.position, Vector3.down, out groundBelow)) {     downwardDirection = new Vector3(groundBelow.normal.x,            (groundBelow.normal.x * groundBelow.normal.x + groundBelow.normal.z * groundBelow.normal.z) /                                             -groundBelow.normal.y ,            groundBelow.normal.z);     downwardDirection.Normalize(); } How it works: Using the Physics.Raycast() function takes the postion where the ray is cast from, the direction that the ray is cast, and the variable which stores the raycast information. The RaycastHit variable type contains the normal vector of the first plane it hit. So how does that help? Well, the equation of a slope that contains the origin is: [note] This isn't the complete equation that takes into account the planes that don't pass through the point  (0,0,0). 0 = a*x + b*y + c*z   We can find an equation that is useful to us using the normal vector of the plane. The normal vector with components <A,B,C> defines the plane when we subtitute -A=a, -B=b, -C=c in the equation of the plane. So: 0 = a*x + b*y + c*z  subtitute -A=a, -B=b, -C=c 0 = -A*x + -B*y + - C*z Now that we have the equation for the plane (which, as in the code, our character's position is directly above), and it's normal vector, we can project the normal vector "down" (more specifically, along the y-axis) onto the plane. Why do we project the normal vector down onto the plane? The reason we use the normal vector to do this is; the normal vector moves away from the plane in the fastest possible direction. So if we want to go "down" the plane as fast as possible, we have to travel in the same left/right and forward/backward direction, but still be on the plane in the up/down direction (in this case "down"). So we have the 'x' and 'z' components of the direction we are traveling in the components of our normal vector, but we need to find the 'y' component on our plane. So we solve the equation of the plane for 'y' to get an equation for how far down we go after traveling so far left/right and forward/backward. 0 = -A*x + -B*y + -C*z slove for 'y' y = (-A*x + - C*z) / B simplify y = -(A*x + C*z) / B or y = (A*x + C*z) / -B Now we plug in or left/right, and forward/backward components into 'x' and 'z' respectively. AGAIN, these happen to be our components of our normal vector.  So: y = (A*x + C*z) / -B plug A in x, and C in z y = (A*A + C*C) / -B or y = (A^2 + C^2) / -B Yay, we have a usable equation for our 'y' component! Now we have to shove all our components into a vector so we have: <A, [(A^2 + C^2) / -B], C> which is a vector traveling in the direction that goes down the y-axis as fast as possible. AND for good measure, I normalized it. [note] normalizing doesn't mean finding a normal vector, it means making the length of the vector = 1. Confusing, right? [hint] If you want to find the normal vector of a plane defined by three point use the cross product and make sure two things, that the three points aren't on the same line and that the direction of your vector is going the correct +/- direction you expect it to. You can use this if you aren't simply hand the correct normal vector like Physics.Raycast() does. That's it. I also used this eqation to find the change in height my character is moving (so he doesn't skip down hills) by replacing 'A' and 'C' with the character's right/left, forward/backward movement (respectively). I hope this helps you out, it certainly would have helped me.