Author Topic: Mounting an object once a projectile hits  (Read 1190 times)

This is very frustrating, no matter what I do I cannot get the player to mount an object.

This is what I've tried(both with a gunitem and a custom staticshape)
Code: [Select]
if(!isobject(%obj.client.player.targetobject)){
%obj.client.player.targetobject = new Item()
{
      position = %obj.client.player.getTransform();
      rotation = "1 0 0 0";
      scale = "1 1 1";
dataBlock = "GunItem";
  };
%obj.client.player.mountObject(%obj.client.player.targetobject,$headSlot);
}

This is in the
Code: [Select]
function ProjectileData::onCollision(%this,%obj,%col,%fade,%pos,%normal){} function, which is in a package.


This is for a stupid workaround I'm attempting in order to get %bot.setaimobject(%object) to aim better, by mounting an object on the player's head and then telling it to aim there.

I could stick a %bot.setaimlocation(vectoradd(%object.getposition(),"0 0 1")); in a fast running schedule but I'd rather let the C++ handle it.
« Last Edit: June 30, 2008, 12:08:32 PM by rkynick »

You say you're trying to get AIPlayer::setAimLocation to work better, but this code looks like it mounts a gun item on a player's head.

Are you trying to mount a bot on a player's head and use the bot to aim the player? If so, it may look something like this:

Code: [Select]
        ...

%player = %client.player;

if( !isObject(%player.targetObject) )
{
%player.mountObject( %player.targetObject = new AIPlayer()
{
dataBlock = %player.getDataBlock();
position = %client.player.getTransform();
rotation = "1 0 0 0";
scale = "1 1 1";
} , $headSlot );
}

        ...

I remember having problems mounting things on players as well.
« Last Edit: June 30, 2008, 11:39:08 AM by exidyne »

He's putting an object on the player's head to use the setAimLocation on, so that bots aim for the head instead of the origin of the player.

Ephi is correct, I'm trying to make a work-around for the "%bot.setaimobject(%player); aims at feet" problem by mounting an object to the players head and have them(the bots) attack there instead.


Hm, the problem might be what I'm mounting, I'll try mounting a player and see if that works.
« Last Edit: June 30, 2008, 12:08:17 PM by rkynick »

Well, it makes no different what you mount.
Can't you just use the player's eye position, then?

Code: [Select]
function ProjectileData::onCollision(%this, %obj, %col, %fade, %pos, %normal)
{
   %obj.targetPosition = %obj.getEyePoint();
}

EDIT:
Ah, I see your dilemma.
« Last Edit: June 30, 2008, 12:22:46 PM by exidyne »

That would probably require me to run a %bot.setaimlocation(%obj.targetposition) over and over in a loop, which I don't want to do.

EDIT:

I managed to get it working by mounting a bot.
« Last Edit: June 30, 2008, 12:57:50 PM by rkynick »

%bot.setAimObject(%player,"0 0 1")?

I saw in a Torque guide that you could add an offset to the function, try using that and adjusting the 1.

I believe that was an addition to the function that appeared in later versions of torque, even if it did work this actually works better than using an offset( I ended up mounting to back, however), if you crouch they still aim correctly(previously with crouching and the offset they would aim above you).

Well, I don't think mounting an item to the player would work because he/she would pick it up. But, the staticshape should've worked with that code.
Maybe MissionCleanup.add(%obj.client.player.targetobject); after it's created.

Using setAimLocation repeatedly on a schedule does have the advantage of letting bots use "advanced" aiming. (e.g. tracking speed like the New Bots Mod or ballistic weapons)