Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you make an object move in 3 directions?
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#11
RE: How do you make an object move in 3 directions?

I made a thing that moves an object!

PHP Code: (Select All)
void MoveObject(float afAmountX, float afAmountY, float afAmountZ, string &in asObject, float afSpace, float afFreq)
{
    if(
GetLocalVarInt("Moving"+asObject) == 1)
    {
        
AddDebugMessage("Object already moving", false);
        return;
    }
    
    
SetLocalVarFloat("MoveFreq_"+asObject, afFreq);
    
    
SetLocalVarFloat("MoveSpace_"+asObject, afSpace);
    
    
SetLocalVarFloat("MoveAmountX_"+asObject, MathSqrt(MathPow(afAmountX, 2)));
    
SetLocalVarFloat("MoveSpaceX_"+asObject, afSpace);
    if(
afAmountX < 0)
    {
        
SetLocalVarFloat("MoveSpaceX_"+asObject, -afSpace);
    }
    
    
SetLocalVarFloat("MoveAmountY_"+asObject, MathSqrt(MathPow(afAmountY, 2)));
    
SetLocalVarFloat("MoveSpaceY_"+asObject, afSpace);
    if(
afAmountY < 0)
    {
        
SetLocalVarFloat("MoveSpaceY_"+asObject, -afSpace);
    }
    
    
SetLocalVarFloat("MoveAmountZ_"+asObject, MathSqrt(MathPow(afAmountZ, 2)));
    
SetLocalVarFloat("MoveSpaceZ_"+asObject, afSpace);
    if(
afAmountZ < 0)
    {
        
SetLocalVarFloat("MoveSpaceZ_"+asObject, -afSpace);
    }
    
    
AddTimer(asObject, 0.0f, "MoveObjectTimer");
}

void MoveObjectTimer(string &in asTimer)
{
    
SetLocalVarInt("Moving"+asTimer, 1);

    if(
GetLocalVarFloat("MoveAmountX_"+asTimer) != 0)
    {
        
SetEntityPos(asTimer, GetEntityPosX(asTimer)+GetLocalVarFloat("MoveSpaceX_"+asTimer), GetEntityPosY(asTimer), GetEntityPosZ(asTimer));
        
AddLocalVarFloat("MoveAmountX_"+asTimer, -GetLocalVarFloat("MoveSpace_"+asTimer));
        if(
GetLocalVarFloat("MoveAmountX_"+asTimer) < 0)
        {
            
SetLocalVarFloat("MoveAmountX_"+asTimer, 0);
        }
    }

    if(
GetLocalVarFloat("MoveAmountY_"+asTimer) != 0)
    {
        
SetEntityPos(asTimer, GetEntityPosX(asTimer), GetEntityPosY(asTimer)+GetLocalVarFloat("MoveSpaceY_"+asTimer), GetEntityPosZ(asTimer));
        
AddLocalVarFloat("MoveAmountY_"+asTimer, -GetLocalVarFloat("MoveSpace_"+asTimer));
        if(
GetLocalVarFloat("MoveAmountY_"+asTimer) < 0)
        {
            
SetLocalVarFloat("MoveAmountY_"+asTimer, 0);
        }
    }

    if(
GetLocalVarFloat("MoveAmountZ_"+asTimer) != 0)
    {
        
SetEntityPos(asTimer, GetEntityPosX(asTimer), GetEntityPosY(asTimer), GetEntityPosZ(asTimer)+GetLocalVarFloat("MoveSpaceZ_"+asTimer));
        
AddLocalVarFloat("MoveAmountZ_"+asTimer, -GetLocalVarFloat("MoveSpace_"+asTimer));
        if(
GetLocalVarFloat("MoveAmountZ_"+asTimer) < 0)
        {
            
SetLocalVarFloat("MoveAmountZ_"+asTimer, 0);
        }
    }
    
    if(
GetLocalVarFloat("MoveAmountX_"+asTimer) == 0 && GetLocalVarFloat("MoveAmountY_"+asTimer) == 0 && GetLocalVarFloat("MoveAmountZ_"+asTimer) == 0)
    {
        
SetLocalVarInt("Moving"+asTimer, 0);
        return;
    }

    
AddTimer(asTimer, GetLocalVarFloat("MoveFreq_"+asTimer), "MoveObjectTimer");
} 

To make it move an object you write

PHP Code: (Select All)
MoveObject(float afAmountX, float afAmountY, float afAmountZ, string &in asObject, float afSpace, float afFreq); 

afAmountX = The amount to move on the X-axis
Can be both positive and negative.

afAmountY = The amount to move on the Y-axis
Can be both positive and negative.

afAmountZ = The amount to move on the Z-axis
Can be both positive and negative.

asObject = The entity to move.

afSpace = The amount of space the object moves with, per frequence.
Must be above 0.
If used with a frequence at 0.01f:
0.01f is kinda slow.
0.02f is quicker.

afFreq = How often the object moves.
Must be above 0.
0.01f looks really smooth.

Variables used in this script:
float "MoveFreq_"+asObject
float "MoveAmountX_"+asObject
float "MoveAmountY_"+asObject
float "MoveAmountZ_"+asObject
float "MoveSpaceX_"+asObject
float "MoveSpaceY_"+asObject
float "MoveSpaceZ_"+asObject
int "Moving"+asObject

Trying is the first step to success.
(This post was last modified: 05-04-2015, 02:00 PM by FlawlessHappiness.)
05-04-2015, 09:44 AM
Find




Users browsing this thread: 2 Guest(s)