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

Heightmap Problems?

14 posts in this topic

Hey everyone,

                       I posted a while back about having issues with heightmaps. I was on Easter break from university so I had to try and get help on-line but I couldn't really understand what I needed to do. I started back at university yesterday and asked my tutor to take a look and he couldn't make help me, he didn't seem to understand the code which is annoying being as I went off the tutorials supplied by my university which were made by said tutor. I'm still seriously stuck on this and I'm starting to run out of places to get help. 

 

Could anyone please help me? My code is a bit long to actually put on the post, besides it's better off if someone who knows what they are doing can see the entire thing so they know exactly where I'm going wrong. I don't want people giving me code or anything like that. I just want someone to look through my program, see where I'm going wrong and talk me through how to fix it, I really want to be able to understand this better.

 

Any help is greatly appreciated.

 

Edit: Just to mention the problem I'm having is that my car in my game is just hovering at a fixed height and phasing through the high sections of the heightmap. As far as I know all the code to alter it's height etc. is there, it just isn't doing anything.

 

Here are just the source files instead of having to download a full program: http://www.mediafire.com/download.php?dwbh8ws11t4oys8

Edited by Phil_93
0

Share this post


Link to post
Share on other sites

Sorry about posting a link to a large file, I wasn't sure what do do because I didn't want people having to trawl though bits of code on a post.

 

I forgot to explain that line, I added it in because I thought it would help me sort my problem out but it just locks my car up so it will only travel in a straight line and my game crashes when the car reaches the side of the heightmap, this is why it was commented out.

 

I'm really stuck, sorry If I'm being a pain.

0

Share this post


Link to post
Share on other sites
You say you added that because you thought it would sort your problem, but where/how were you calling GetHeight before you added that?

Correcting for terrain height is a simple matter of querying the heightmap for the height, and correcting the Y value of the position. So perhaps after applying translationThisFrame to position in Car.cs, you could then calculate the heightmap value, correct position.Y, then construct your world matrix. This would also serve to put this height correction inside of Car where it would make more sense than putting it inside Game.
0

Share this post


Link to post
Share on other sites
Yeah, I'm not too good with this and I tried a lot of different things before asking for help, I also tried changing some of the effect. lines at the bottom of the heightmap class. Oh right, so I'd be better off putting GetHeight in the actual car class rather than trying to pass it through the Update or Draw in the main game? Most of the time when I try to implement GetHeight I get errors. Thank you so much for helping out by the way.
0

Share this post


Link to post
Share on other sites
Well, typically the Physics system would handle this sort of thing, rather than the Game class or the Car class where it currently resides. In physics-enabled applications, the Physics subsystem will integrate the simulation, apply any collision correction to fix penetrations, then notify the participant objects of their new transforms. In your current model, though, there just aren't very many elegant answers to your question. Integrating movement/physics into the object methods like this presents you with some issues that may come back to bite you later:

1) Visibility of the Heightmap to Car. Since Car is responsible for its own movement and physics, it needs to be aware of the world. That means, it'll have to have a reference of some sort to the Heightmap so that during UpdateDrive it can call GetHeight to correct its Y coordinate. This adds a dependency upon Heightmap to Car, so that any change to Heightmap requires changes or, at least, recompilation for Car. It will also have to have access to whatever organizational structure you use to hold all cars, in order to correct for collisions with other cars and objects. This can create circular dependency chains and knotty logical issues.

2) Different versions of Car for Player or AI controlled cars. If you decide to implement AI cars, you'll need a different version of Car from what you have now since an AI car wouldn't respond to controller input. So that means either duplicating update code, or refactoring Car into a hierarchy (a thorny, twisted road to go down in a game of any sort of complexity).

3) Modifying the simulation could mean modifying code spread out across many modules. Say you want to add gravity to the simulation, rather than just clamping Y values directly to the heightmap surface. This would facilitate, for example, jumping and falling. However, if the physics are spread out among all the various participating object classes (PlayerCar, AICar, etc...) then you have to go and correct each participating class's Update methods with the new code. Make sure you get them all, because if you forget to enable gravity for one then it will not behave uniformly with the remainder of the objects. And if later you decide to tweak something else, then again you need to traverse the entire codebase modifying each class Update method to account for it.

In a simulation that is built upon an actual physics library (rather than homegrown gestalt update methods) then actual movement, collision correction, etc... are encapsulated in a physics subsystem whose sole responsibility is to integrate the physics and move stuff around. Individual cars don't move themselves; they simply apply, or inject, forces into the system. Pressing the accelerator, for example, would inject a linear impulse in one direction, tapping the brake would inject a linear impulse or some other form of decelerating impulse in another. Holding the thumbsticks for steering would inject angular impulses. And so on. But the actual movement of objects would be encapsulated within the physics system, acting upon the properties set for a given object, and pushing transform matrices back out to the participating objects after the simulation step is performed. In this way, changes to the Physics subsystem are confined to a single module rather than spread out across several classes, and behavior is shared among all types of objects without introducing any kind of dependencies between those types.

It is for architecture questions like this that people have begun to strongly recommend composition-based systems rather than concrete classes such as Car. If your game were to progress along your current curve toward a fairly complex simulation, you would find an exponential increase in the difficulty of maintaining and modifying it. Eventually, for example, you might want to implement other vehicle types: motorcycles, trucks, jet-powered cars, etc... And you find yourself either building horrible, complex hierarchies and trying to shoehorn every vehicle type into it, or duplicating a horrendous amount of code across multiple discrete classes. Either way, it becomes more and more of a nightmare trying to maintain it, and significant changes to the simulation will require significant changes to large portions of the codebase.
2

Share this post


Link to post
Share on other sites

I haven't looked your code, but when I used a heigthmap on Panda3d I had a similiar problem, maybe they use the same approach.

 

When you use a heightmap the heights will be between 0 and 255 (or normalized in the interval [0, 1.0]). In this case you need to use an upper axis scale that is applied to every pixel . If you are only getting the position height, you might have apply the same scale to find the actual upper axis coordinate.

1

Share this post


Link to post
Share on other sites

I feel really stupid for saying this but a lot of that just went straight over my head (It's my own fault I should have said to keep it simple, I'm fairly new to programming. Even more so to xna). My university is giving us code/tutorials that doesn't work properly and not even the tutors seem to understand their own stuff.

 

I've been trying to do this for about 4 weeks straight now and I'm getting to the point where I just want to give up and go home. It's starting to look like university isn't for me.

0

Share this post


Link to post
Share on other sites

I feel really stupid for saying this but a lot of that just went straight over my head (It's my own fault I should have said to keep it simple, I'm fairly new to programming. Even more so to xna). My university is giving us code/tutorials that doesn't work properly and not even the tutors seem to understand their own stuff.
 
I've been trying to do this for about 4 weeks straight now and I'm getting to the point where I just want to give up and go home. It's starting to look like university isn't for me.

Don't give up. Sorry for getting a bit advanced there.

To get back to the code as presented, try to break it down into the exact steps that are occurring here.

1) Input is polled to get the positions of the thumbsticks and triggers. These values are used to determine forward/backward movement and turning.

2) Objects are moved (updated) based on this input.

In Car::UpdateDrive, this sequence of actions occurs:
1) Translation for the frame is calculated, based on the input
2) New position for the car is calculated by translating the old position by the input translation.
3) New direction is calculated based on the input
4) New world matrix is calculated for the car to be drawn

When you added the line
//player.world = Matrix.CreateTranslation(player.yaw, terrain.GetHeight(player.position), player.pitch);
to Game1.cs, you basically negated everything that was done in Car::UpdateDrive, setting the world matrix for player directly. As you discovered for yourself, that wasn't the correct thing to do. But if you analyze exactly what UpdateDrive is doing, you might be able to deduce when the best time to correct the Y location is: right after the new position is calculated, but before a new world matrix is constructed for the object. So if you were to add some sort of code to UpdateDrive, right after the new position is calculated, that will call the Heightmap, get the height for the new position, and set the new position's Y value to this height, then it should work.
2

Share this post


Link to post
Share on other sites

Thank you so much for the help. I'll go and have a try now. 

 

I just hope I'm not being annoying or anything.

0

Share this post


Link to post
Share on other sites

Ok, good news and bad news.

 

Good news is, I finally got it to work! my car is adjusting it's height according to the heightmap.

 

Bad news is, I'm now underneath my heightmap for some reason.

0

Share this post


Link to post
Share on other sites

Ok, good news and bad news.

 

Good news is, I finally got it to work! my car is adjusting it's height according to the heightmap.

 

Bad news is, I'm now underneath my heightmap for some reason.

 

Always by the same amount? Don't you need to add the car size? Is you car scaled maybe?

0

Share this post


Link to post
Share on other sites

Hey sorry I went quiet yesterday, I needed a break. Looking at it today I have actually changed the scale of the car in the properties.

 

I'm guessing I need to multiply or add the scale of the car to the line that changes it's Y position on the heightmap?

0

Share this post


Link to post
Share on other sites

Actually scratch that I've changed the camera around so I can look around and I'm actually way above my heightmap, it looks tiny from where I actually am.

0

Share this post


Link to post
Share on other sites

Ok great news! My car is finally sticking to the ground as it should! The frame rate is dropping a little when the car moves forward but I'm sure I can fix that somehow, it is only a minor problem after all.

 

Just want to say thanks to everyone that helped me out on this otherwise I'd have never got it done.

 

Thanks everyone!

Phil_93 :D

0

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