Game Development Community

Homing script

by Wolf Okami · in Technical Issues · 11/25/2008 (2:34 pm) · 6 replies

Ok this may sound odd but say I wanted a character(me) to tap jump twice to home in on an enemy(Sonic Adventure)

It would be like sonic adventure for reference if any of you heard of that.

I probably can figure it out if i get a basic onJump timing script to trigger another action while jumping if pressed twice
sort of like a double jump but instead of the double jump part im hurled at the enemy from any direction to that enemy

#1
11/25/2008 (3:22 pm)
NOT REAL CODE:
if (JUMP)
{
    if (jumpTimer$ < 1sec)
        HomingJump();
    else
        Jump();
    jumpTimer$ = 0;
}

And for you homing jump do a container search with n radius. Determine the nearest enemy within the search results. Do some vector math trickery and move the player towards/to that location.
#2
11/25/2008 (3:40 pm)
Hmph ill have to research that lemme ask you this, can you use c++ in torque i mean will it work? or do you have to use torque script.

I might be able to find C++ script for that

Another thing thats not real code?
What is the actual code for jump timer manipulation, and number of times you can jump, and also the projection of the jump(x,y,z) and the velocity of the jump. Do i need to add more variables and equations to this:

jumpForce = 8.3 * 90;
jumpEnergyDrain = 0;
minJumpEnergy = 0;
jumpDelay = 15;

If so where or if not how? Show me an example and ill probably understand it
#3
11/27/2008 (6:44 am)
Seriously i want to know how and where to put it
#4
11/27/2008 (7:19 am)
Well if you have access to the source code, which i see you don't, then you would be able to use c++ but you are limited to torque script at the moment.

So ill help you out a little bit,

I would solve this by using "command to server" calls so that the jump system would work correctly over network. Then i would put in my servercmd function something like
if (JUMP)
{
    if (jumpTimer$ < 1sec)
        HomingJump();
    else
        Jump();
    jumpTimer$ = 0;
}

like Micheal stated above, but since this is not real script code that would work out of the box i would have to change it to suit the needs of the feature. So now i would reformat the code to read :

function serverCmdJump(%client)
{
   %player = %client.player;
   %player.jumpSched = schedule(3000, 0, "resetJump", %player); // make it 3 seconds for testing purposes
   %player.jumped = false;

   if(%player.jumped)  // if the player has already jumped
   {
       DoHomingAttack();
       echo("-->Current Weapon is " @ %weaponName);
      cancel(%this.jumpSched); // dont want this to end up in some kind of loop or something
   }
   else if(!%player.jumped) //or if this is his first time jumping
   {
      Jump();
      %player.jumped = true; // if its his first time then set this to true so he will home next time this function is called
      echo("-->just regular jumping");
   }
}

//=================================
//         NOW FOR THE JUMP RESET FUNCTION
//=================================

function resetJump(%player)
{

   %player.jumped = false;
   echo("-->resetting jump flag");
}

Please not that this is code off the top of my head but does conform to torque script syntax. Now with thos functions you should be able to write your own homing attack function.

Happy Coding
Oh and Happy Thanksgiving to all

edit
Had to fix some of the errors in the example :D
#5
02/19/2009 (6:11 pm)
Coudn't I in theory create an animation and the load the dsq bind it and then put a magnet script with a cutoff after so many seconds? the only problem is i do not have the original model so i would have to do it your way...

But i guess the real question is, is there a magnet script with a default timer and can i make it load after the jump action is performed.

either way seems logical but this is torque after all
#6
02/19/2009 (6:18 pm)
i could work wonders if i had one of those nifty scripts
all i would have to do is bind the jump button with the new function and make it only accessible after the first jump function had preceeded it. then the magnet script would come into effect


technically i could make it so the function would only be performed if the target was within a radius.