View unanswered posts | View active topics It is currently Sat Dec 28, 2024 3:37 pm



Reply to topic  [ 4 posts ] 
 Question about aim distance 
Author Message

Joined: Sat Dec 04, 2010 4:48 am
Posts: 13
Reply with quote
Post Question about aim distance
Hi all.
i have a question about the aim distance.
there is a function in lua that can get the actor's AimAngle. however is there anyway to know the aim distance of an actor?

I've searched around in this forum and i found the actor.ViewPoint. it is said that this variable represents the aim position of the actor, but in game i found that its value is not what i supposed it to be:
When i move the mouse to the right side of the actor, the console shows that the aim offset (which is actor.ViewPoint - actor.EyePos) is something close to (50, 0) and that seems correct. But if i move the mouse farther to the right, this aim offset doesn't grow to (200, 0) or something like that. it seems that the X and Y of this aim offset will never exceed 70 though my weapon's SharpLength is more than 300 pixels and i'm aiming at long range targets.

Actually i'm modding a adjustable-initial-velocity grenade launcher. The grenade will have higher initial velocity if i aim farther and vice versa so the weapon can be used in various situations. Now i can only use SceneMan:GetOffset(0) + Vector(320, 240) to get the center position of the camera ( i have my game running with resolution of 640*480 and i don't know how to get those data in lua script so i just hard-coded them ) and then use the SceneMan:ShortestDistance() with the actor's eye position to get the distance for reference of the initial velocity of the grenade. it does work in normal games now, but i don't think it will be when in multi-player situations in which each player has its separated screen area.

So i'd like to know if there is anyway to get the aim distance of an actor in lua script?


Sun Feb 12, 2012 7:23 am
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Question about aim distance
I can't say what you are doing wrong without seeing any code, so I wrote you a weapon script that calculates the distance between the aim point and the muzzle every time the weapon is fired:

Code:
function Create(self)
   if self.Magazine then
      self.ammo = self.Magazine.RoundCount
   else
      self.ammo = 0
   end
end

function Update(self)
   if self.Magazine then
      if self.ammo > self.Magazine.RoundCount then
         -- bullets are missing from the magazine so the gun must have been fired
         
         local Parent = MovableMan:GetMOFromID(self.RootID)
         if MovableMan:IsActor(Parent) then
            print("distance: " .. SceneMan:ShortestDistance(ToActor(Parent).ViewPoint, self.MuzzlePos, false).Magnitude)
         end
      end
      
      -- update the ammo counter so this script can't spawn bullets until the gun has been fired again
      self.ammo = self.Magazine.RoundCount
   end
end



Tue Feb 14, 2012 10:11 am
Profile

Joined: Sat Dec 04, 2010 4:48 am
Posts: 13
Reply with quote
Post Re: Question about aim distance
Abdul Alhazred wrote:
I can't say what you are doing wrong without seeing any code, so I wrote you a weapon script that calculates the distance between the aim point and the muzzle every time the weapon is fired:

Code:
function Create(self)
   if self.Magazine then
      self.ammo = self.Magazine.RoundCount
   else
      self.ammo = 0
   end
end

function Update(self)
   if self.Magazine then
      if self.ammo > self.Magazine.RoundCount then
         -- bullets are missing from the magazine so the gun must have been fired
         
         local Parent = MovableMan:GetMOFromID(self.RootID)
         if MovableMan:IsActor(Parent) then
            print("distance: " .. SceneMan:ShortestDistance(ToActor(Parent).ViewPoint, self.MuzzlePos, false).Magnitude)
         end
      end
      
      -- update the ammo counter so this script can't spawn bullets until the gun has been fired again
      self.ammo = self.Magazine.RoundCount
   end
end



Thanks for the codes. I'm modding the Coalition's Revolver cannon.
Today i did several tests and i figured out that the actual reason why the ViewPoint i get in the grenade's Create() function is incorrect:
the Revolver cannon has a recoil effect when it fires. and the camera will be dragged back. which cause the ViewPoint to be much closer than what i want.

Any way to disable that recoil? i found that the Revolver cannon has already used the tricks of using an AEmitter to spawn the actual shots instead of the HDFirearm itself, just like the Heavy Sniper Rifle. that sniper rifle works good, no recoil at all. but no matter how i change the ini, the revolver cannon's recoil is still there.

Here is my ini and lua.


Attachments:
RevolverCannon.ini [9.97 KiB]
Downloaded 185 times
RevolverDetonator.lua [3.84 KiB]
Downloaded 165 times
Tue Feb 14, 2012 6:09 pm
Profile

Joined: Sat Dec 04, 2010 4:48 am
Posts: 13
Reply with quote
Post Re: Question about aim distance
:) After another tens of tests, i finally got the line that caused the problem:

in the definition of Revolver Cannon Shot, there is :
Code:
GetsHitByMOs = 1


And i guess it is because this AEmitter got hit by the gun or actor or whatever. then that force is impact on the actor finally.
After changing that line, the problem got fixed and now, i finally have the gun works perfectly.
:grin: Thanks again to your help.


Wed Feb 15, 2012 2:12 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: Google [Bot]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.031s | 15 Queries | GZIP : Off ]