Game Development Community

Question about getRotation()

by Jesse Hall · in Torque Game Builder · 07/05/2005 (9:45 am) · 8 replies

Is the value returned by getRotation() an angle? I have a formula my friend helped me out with and it needs an angle to work.

I am trying to find a point that is ahead of the player and rotates with the player.

Here is the math im using.

dollyX = playerX + offset * cos (angle)
dollyY = playerY + offset * cos (angle)

any help is appreciated =)

#1
07/05/2005 (10:00 am)
Yes :) To test it I created a player

$player = new fxStaticSprite2d() {scenegraph = t2dSceneGraph; };

Then set its angular velocity to 15

$player.setAngularVelocity(15);

then kept getting its rotation

echo($player.getRotation());

and it returned the player's angle from 0 - 359
#2
07/05/2005 (1:35 pm)
Jesse, another thing you can do, if you want to have access to a point in front of a sprite, is create a link point.

Like:
$player.lookPoint = $player.addLinkPoint( "0 -1" );
// then you can get at it like
%worldPos = $player.getLinkPoint( $player.lookPoint );
This will create a linkpoint one unit in "front" of the $player. You can get the coords of that point at any time.

note that "$player.lookPoint" is just storing the idex to the link point inside the namespace of $player, for easy reference. You could store that index anywhere.
#3
07/05/2005 (2:18 pm)
Can link points be modified on the fly? I am creating a camera dolly that will increment out based on the speed the player is traveling. I suppose i could keep reasigning the link point but doing that everytime i update player position seems wrong.
#4
07/05/2005 (4:21 pm)
Yeah, that's probably not the best way to do it then. So you're trying to just get the speed the $player is moving? If so, what about "getLinearVelocityPolar()"?
#5
07/05/2005 (5:10 pm)
I have the players forward and backward movement bound to "w" and "s" and then just increment or decrement a variable $cameraOffset to get the distance i want the camera dolly to project out from the player. The $speed variable is independent but gets incremented and decremented in the same functions that fire for the forwards or backwards. Once i get it figured out ill even tweak it so the dolly will project slightly ahead in the direction of the rotation to give the max viewing area ahead of the player.
#6
07/05/2005 (7:14 pm)
Got it but there is some slipage that causes camera jitters.. not sure how to fix that but im on working on it.

//
// update positions
//

function updatePositions()

{     
	$rotation = $player.getRotation();
	$player.setLinearVelocityPolar( $rotation, $speed );
	$tankTurret.setRotation( $turRot );
	%dollyPosX =   ($player.getpositionX() + $cameraOff*(mCos(mDegToRad($rotation-90))));
	%dollyPosY =   ($player.getpositionY() + $cameraOff*(mSin(mDegToRad($rotation-90))));
	$cameraDolly::player.setPosition( %dollyPosX SPC %dollyPosY );
	schedule(1, 0, "updatePositions");

  }
#7
07/06/2005 (12:44 am)
Interesting stuff. I kind of like the effect. I did some playing around with it. Maybe you've dug this up on your own, but anyway, here's what I found:
// set up camera move parameters
sceneWindow2D.setCameraInterpolationMode("LINEAR");
sceneWindow2D.setCameraInterpolationTime( 0.06 );

// sample update function
updateCamera();
//
//.....
//
function updateCamera()
{
	%rotation = $player.render_unit.getRotation();
	%dollyPosX =   ($player.render_unit.getpositionX() + $cameraOff * (mCos(mDegToRad(%rotation-90))));
	%dollyPosY =   ($player.render_unit.getpositionY() + $cameraOff * (mSin(mDegToRad(%rotation-90))));
	sceneWindow2D.setTargetCameraPosition( %dollyPosX SPC %dollyPosY SPC "100 75" );	
	sceneWindow2D.startCameraMove( );
	schedule( 60, 0, "updateCamera");
}
so what this does, and I didn't know this about cameras until I started playing around with this, is it sets up a target position for the camera to move to, then "startCameraMove()" tells the camera to move to that position. The init stuff like"setCameraInterpolationTime()" sets the time (in seconds) it takes a camera to reach a position. I set it to 0.06 to match the schedule time of 60 ms. Play with it to get something smooth, but too slow will be jerky. This one is nice and smooth though.

Neat stuff... I hadn't played with camera functions before.
#8
07/07/2005 (12:53 pm)
Interesting..

unfortunately it didnt really clear it up for me. With low speeds its hardly noticeable but with the high speeds im going for its to much.

the camera functions have my interest though. ill have to play with them and see if i can get a solution there. thanks!