Game Development Community

Mounting Question

by Konrad Carstein · in Torque Game Builder · 06/27/2008 (9:14 pm) · 7 replies

This I'm sure has a simple answer but for the life of me it eludes me.

I want to mount object A, to object B

I've created a link point on the far left side of object B and a link point on the far right side of object A.

I simple want to mount them "end to end".

However it only wants to mount the center of object A to the link point on object B.

Why does the center of the object, say a 128x128 image always get snapped to the the link point. Howe to I mount these two object to the ends of each other?

Thanks!

#1
06/27/2008 (11:38 pm)
I was thinking of the exact same thing the other day. I think it was done for a reason, the only thing I could think of was relates to scene objects only being able to rotate around their own center, and not an arbitrary pivot point.

Anyways, I suggest that you create a blank t2dSceneObject (object C) twice the width of object A with a mount point at (0.5, 0.0). Mount object A to C, then C to B.

As long as everything there is cosmetic, you wont have too much of a problem. Stuff might get funky with collisions, but that is another kettle of worms =P
#2
06/27/2008 (11:51 pm)
Every time I expect a simple answer...denied. Thank you so much for the response though, even if it is a bit more complicated then I'd like.

Let me look at this from a different angle, perhaps I'm going about it the wrong way. I am essentially trying to mount a simple weapon to the player. I went this route so that I could attempt to handle collision with the weapon differently then collisions with the player.

I am curious though because in some of the images I've seen in the platformer tutorials, draw the weapon (in that case a sword) right along with the player. How are collisions handled then? Would you mount and invisible object on top of the player and define separate collision points surrounding the drawn in weapon?

Thanks
#3
06/28/2008 (12:06 am)
Melee combat is always a difficult problem to deal with. You could use an invisible object to handle the collision, but I think a simpler method would be to use collision normals.

Something like this:

function myClass::onCollision(%ourObject, %theirObject, %ourRef, %theirRef, %time, %normal, %contacts, %points)
{
    if (!%theirObject.isBadGuy)
        return;
 
    if (((!%ourObject.getFlipX() && %normal.X > 0) || (%ourObject.getFlipX() && %normal.X < 0)) && %ourObject.isAttacking)
        %theirObject.takeDamage();
    else
        %ourObject.takeDamage();
}

Obviously this is an over simplification, but what that is saying if the collision happened in front of us, while we're attacking then they take some damage, otherwise we take it.
#4
06/28/2008 (5:41 am)
Mounting objects throws a whole toolbox of monkey wrenches into animation too. You have to adjust mount points and animate the object separately. I'd suggest doing all one image, and something like Phillip suggests.
#5
06/28/2008 (4:12 pm)
Excellent advice as always guys. I was once a little perplexed by the use of normals, but I think I've got it down pretty good. But here is just a little bit of wierdness I'm having trouble with. This code is similar to Phillip's above, but I've added my own (not working) flavor to it.

function EnemyClass::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts){
 
   if(%dstObj.class $= "PlayerClass"){

      if(%normal.Y < 0){

         if(%dstObj.isAttacking){
            echo("before dmg");
            echo("enemy name: " @ %srcObj.getName());
            echo("player name: " @ %dstObj.getName());   
            %srcObj.takeDamage(%srcObj,%dstObj);
         }
      }
   }
}

function EnemyClass::takeDamage(%srcObj,%dstObj){
   
   echo("after dmg");
   echo("enemy name: " @ %srcObj.getName());
   echo("player name: " @ %dstObj.getName());   
   
   %srcObj.health = %srcObj.health - %dstObj.dmg;

   if(%srcObj.health <= 0){
        
      %srcObj.safeDelete();
   }
}

So basically on my takeDamage() method, I assume I'm passing in the instance of the srcObj ( in this case the enemy), and the instance of the dstObj (the player).

I simply want to subtract the amount of dmg the player does, from the amount of health the enemy has.

But what is wierd, is when the echo statements print i get the following:

before dmg
enemy name: enemy1
player name: player1
after dmg
enemy name: enemy1
player name: enemy1

and so the dmg doesn't get subracted because the enemy object doesn't have a dmg value. They now seem to be references to the same object? What am I missing?
#6
06/28/2008 (4:36 pm)
You are calling the function:

%srcObj.takeDamage(%srcObj,%dstObj);

You should be using:

%srcObj.takeDamage(%dstObj);

Remember, the first variable in the function call is the object that you call ;)
#7
06/28/2008 (5:03 pm)
Ah, thank you. Sheesh. I'm a java programmer by trade, so I'm no stranger to OO programming. Torquescript is just enough OO so that I get it, but just far enough from it that things like this mess with me.

I look at the signature of a function and assume that is how it should be called. But in actuality anytime you call a method...er function then the instance of the object calling the function is always the first param. I'll put that on a sticky note at my computer I think.

Thanks again!!