Gravity Component - TX2D
by Austin Whitlatch · in Torque X 2D · 07/12/2008 (10:26 am) · 3 replies
I am trying to create a simple gravity component for my platformer game. A static fall will not work and would like to use a function similar to that of gravity. But I have ran into a small problem. I have found that when I create a 'T2DSceneObject' it is a local variable that doesn't grab the objects TOTAL velocity, just a local velocity that is destroyed at the end of the process tick. All I really want to do is do Velocity.Y += 1.0f, but instead of getting the results of 1,2,3,4,5,etc. I am getting 1,1,1,1,1. Can anyone help me out? I'm new to this and it doesn't translate well to any other programming that I've ever done. If anyone knows where I can find ANY documentation on TorqueX that shows you HOW to do something in TorqueX not just telling you WHAT it can do, I'd greatly appreciate it.
About the author
#2
Thanks for the advice. I had thought of that, but what I wanted was a component to update the ball's movement as if the ball were being PULLED by gravity. I saw a ForceComponent on a forum that talked about making a MasslessForce with a ConstantDirection equal to 180 and enabling ConstantDirectionIsWorldSpace. The only problem is that it didn't work like it was supposed to :( The ball doesn't move with that enabled. I don't know why it doesn't work, but that would be my preferred method if I were able to get it to work. If I'm doing something wrong on the setup, I'd like to know.
Thanks much :)
Austin
07/12/2008 (2:04 pm)
Hey John,Thanks for the advice. I had thought of that, but what I wanted was a component to update the ball's movement as if the ball were being PULLED by gravity. I saw a ForceComponent on a forum that talked about making a MasslessForce with a ConstantDirection equal to 180 and enabling ConstantDirectionIsWorldSpace. The only problem is that it didn't work like it was supposed to :( The ball doesn't move with that enabled. I don't know why it doesn't work, but that would be my preferred method if I were able to get it to work. If I'm doing something wrong on the setup, I'd like to know.
Thanks much :)
Austin
#3
07/13/2008 (12:20 am)
Heres another example, using Johns code.. here you Velocity is increased by 1 every second. class mycomponent: TorqueComponent, ITickObject
{
Vector2 Velocity = Vector2.Zero;
public void ProcessTick(Move move, float elapsed)
{
totalElapsed += elapsed;
if (totalElapsed > 1)
{
Velocity.Y += 1.0f;
totalElapsed = 0;
}
//update the velocity for this tick
}
float totalElapsed;
}
Associate John Kanalakis
EnvyGames
class mycomponent: TorqueComponent, ITickObject { Vector2 Velocity = Vector2.Zero; public void ProcessTick(Move move, float elapsed) { //update the velocity for this tick Velocity.Y += 1.0f; } }Try something like that.
John K.