Game Development Community

How to implement movement costs?

by Todd Barron · in Torque Game Engine · 04/22/2006 (8:17 pm) · 4 replies

I'm currently trying to port my 2D game into 3D via Torque. My game is a turn-based strategy one in which units can move x-number of spaces depending on the terrain.

For instance:

1. Tank starts with 10 movement points
2. Tank drives on road (tiles) for 4 spaces at a cost of 1 point per space
3. Tank now has 6 movement points left
4. Tank now drives on grass (tiles) for 3 tiles at a cost of 2 points per space (grass is harder to move on)
5. Tank now has 0 movement points left

Is there any way to figure out the terrain type the vehicle is on with the torque terrain? In my 2D game I have a tile-grid with movement costs associated to each tile. I could do this in 3D with another "hidden" grid but it would be nice to have vehicle movement be limited by terrain texture, not a hidden grid (would be more accurate.)

Has anyone else tried this?

#1
04/23/2006 (12:22 am)
You can do a cast ray or ray cast. Not sure which. You can search on that. I have done it from C++ for vehicles, but not in script. You will have to search around for the commands. In C++ you will get a structure that defines what you hit the type, the terrain texture and other stuff like distance. I don't know what you get for the script version.
#2
04/23/2006 (7:50 am)
I'm almost sure the script callback doesn't return material information, but you could modify it to do so, since such capability is avalaiable within the engine.

There is a resource derived from the fxGrass resource, which allows the grass placement to be affected by terrain materials. Maybe that could be of help.
#3
04/23/2006 (8:28 am)
Maybe try to piggyback on the existing torque system
which decides what footstep sound to play
depending on what material you're on
#4
04/23/2006 (9:37 am)
@Orion: Hmm, that may be the easiest approach (which usually is the best approach.) I'll give it a try. Thanks everyone for the feedback!