Game Development Community

How to do a vehicle rotating wheel effect

by Christopher McKenzie · in Torque Game Builder · 05/19/2009 (8:36 pm) · 1 replies

Hi all. I've had TGB for a while now and just recently put together all the art assets I need to begin cobbling together on a prototype I've had in mind.

I'm trying to put together a motorcycle with rotating wheels. The motorcycle will be the main actor so I'll want to setup a behavior script to control it. I'm guessing that I'll have to put together a script to both rotate the wheels and keep them in line with the body of the motorcycle while its being moved.

Any tips on how to go about this? I've only just gotten my scrolling planes looking good so I'm still in the middle of trying to figure out what's actually possible with Torque script.

Thanks!

About the author

Recent Threads


#1
06/11/2009 (1:05 pm)
What you could do is make the motorcycle object create two wheels at startup, and make the child wheels spin based on the motorcycle's speed. For example:

----------

//-----create motorcycle wheels at startup-----
function Motorcycle::onLevelLoaded(%this) {
%this.motorcycle = new t2dStaticSprite() {
scenegraph = %this.scenegraph;
class = wheel;
parentCycle = %this;
};
}

//-----motorcycle update function-----
function Motorcycle::onUpdate(%this) {
%this.wheel.spin();
}

//-----wheel spin function-----
function Motorcycle::spin(%this) {
%this.setRotationalVelocity(%this.parentCycle.getLinearVelocityX());
}


----------

It's been awhile since I've programmed, so that code probably won't work :P