View unanswered posts | View active topics It is currently Fri Dec 27, 2024 8:47 am



Reply to topic  [ 15 posts ] 
 Mouse position? 
Author Message
User avatar

Joined: Fri Dec 28, 2007 4:19 am
Posts: 1119
Reply with quote
Post Mouse position?
How do I get mouse position? Something sort of finding the point where the sharp aim dots are.

As well, how do I get forward vectors of an object? And playing sounds via lua.


Thu Nov 19, 2009 4:54 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Mouse position?
Quote:
How do I get mouse position? Something sort of finding the point where the sharp aim dots are.
I don't know this, although I have always been wondering about it.


Quote:
As well, how do I get forward vectors of an object?
Do you mean how fast something is going in its direction? That would be "object.Vel.Magnitude"


Quote:
And playing sounds via lua.
Currently, the only way is to spawn something that would make a sound, no pure Lua method. Who ever made the base teleporters spawn an emitter with the burst sound for the sound, which seems like the simplest option to me.


Thu Nov 19, 2009 11:39 pm
Profile
User avatar

Joined: Fri Dec 28, 2007 4:19 am
Posts: 1119
Reply with quote
Post Re: Mouse position?
I'm meaning the from point A and the vector going to point B, I'm using this in the CastObstacleRay function.


Thu Nov 19, 2009 11:47 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Mouse position?
Code:
object.Vel = Vector(pointB.X-pointA.X,pointB.Y-pointA.Y):SetMagnitude(#);


Replace # with the speed you want.


Fri Nov 20, 2009 1:02 am
Profile
User avatar

Joined: Fri Dec 28, 2007 4:19 am
Posts: 1119
Reply with quote
Post Re: Mouse position?
Code:
function Update(self)

   self.Pos = self.owner.Pos + Vector(0,-50);
   self.Vel = self.owner.Vel;
   if self:IsEmitting() == true then
      self:EnableEmission(false);
   end
   --self.RotAngle = self.Owner:GetAimAngle(false);
   if self.ToSettle == true then
      self.toDelete = true;
      self.owner.gunpodOn = false;
   end
   --if self.owner:IsPlayerControlled() == false then
      --Fing a target not on same team
       local curdist = 500;
       for actor in MovableMan.Actors do
         local avgx = actor.Pos.X - self.Pos.X;
         local avgy = actor.Pos.Y - self.Pos.Y;
         local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
         if dist < curdist and actor.Team ~= self.Team then
            curdist = dist;
            self.target = actor;
         end
      end
      --local targetdir = math.atan2(-(self.target.Pos.Y-self.Pos.Y),(self.target.Pos.X-self.Pos.X));
      --RayDistance = SceneMan:CastObstacleRay(self.Pos, self.target.Pos, Vector(0, 0), Vector(0, 0), self.ID, 0, 5);
      --TargetDist = math.sqrt((self.target.Pos.X-self.Pos.X)^2 + (self.target.Pos.Y-self.Pos.Y)^2);
      --print(RayDistance);
      --print(TargetDist);
      if MovableMan:IsActor(self.target) then --and RayDistance >= TargetDist then
         --The direction from the center of the missile to the target.
         local targetdir = math.atan2(-(self.target.Pos.Y-self.Pos.Y),(self.target.Pos.X-self.Pos.X));
         
         if targetdir ~= self.RotAngle then
            self.RotAngle = targetdir;
         end
         if self:IsEmitting() == false then
            self:EnableEmission(true);
         end
      else
   
         self.HFlipped = self.owner.HFlipped;
         self.RotAngle = 0;
         if self:IsEmitting() == true then
            self:EnableEmission(false);
         end
      end
   --elseif self.owner:IsPlayerControlled() == true then
      --self.HFlipped = self.owner.HFlipped;
   --end
   
   --If owner is dead, gib self.
   
   if self.owner:IsDead() == true then
      self.ToDelete = true;
   end
end


I'm basically doing a helper gunpod, but I'm trying to get it so that it can only shoot at what it can "see" hence the want for the castobstacleray, I need it to check if there's anything between the target and the gunpod. So it won't shoot though walls, shoot the owner...


Fri Nov 20, 2009 2:17 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Mouse position?
A StrengthRay would work in place of an ObstacleRay.

This would work for you:

Code:
local terrcheck = Vector(0,0);
if not(SceneMan:CastStrengthRay(self.Pos,Vector(self.target.Pos.X-self.Pos.X,self.target.Pos.Y-self.Pos.Y):SetMagnitude(500),0,terrcheck,3,0,true)) then


Fri Nov 20, 2009 2:29 am
Profile
User avatar

Joined: Fri Dec 28, 2007 4:19 am
Posts: 1119
Reply with quote
Post Re: Mouse position?
Alright works, but why not ObstacleRay? Just wondering.


Fri Nov 20, 2009 4:16 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Mouse position?
No real reason, just that I have no experience with ObstacleRays. BTW, I thought about this a little bit at school, and you should try:

Code:
local terrcheck = Vector(0,0);
if not(SceneMan:CastStrengthRay(self.Pos,Vector(self.target.Pos.X-self.Pos.X,self.target.Pos.Y-self.Pos.Y),0,terrcheck,3,0,true)) then


The previous version would cast the ray too long and the turret may not fire at enemies in front of walls.


Fri Nov 20, 2009 11:25 pm
Profile
User avatar

Joined: Fri Dec 28, 2007 4:19 am
Posts: 1119
Reply with quote
Post Re: Mouse position?
Works better, but it doesn't seem to check if the owner is between it and the target, had it eat the head off... Is it good to use a MORay with it? So if the parent's ID is returned...


Fri Nov 20, 2009 11:56 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Mouse position?
Yes, MORays would work too. Be sure to set the "material ID to ignore" to 0.


Sat Nov 21, 2009 12:08 am
Profile
User avatar

Joined: Fri Dec 28, 2007 4:19 am
Posts: 1119
Reply with quote
Post Re: Mouse position?
Working on another lua based weapon now, what's the property name for MOSRotatings in the moveable manager?


Thu Nov 26, 2009 2:07 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Mouse position?
MovableMan.Particles, and then check for if particle.ClassName == "MOSRotating"


Thu Nov 26, 2009 3:09 am
Profile
User avatar

Joined: Fri Dec 28, 2007 4:19 am
Posts: 1119
Reply with quote
Post Re: Mouse position?
What if I want to run a function like GibThis(); How does type casting happen in lua?


Thu Nov 26, 2009 4:40 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Mouse position?
I'd do
for particle in MovableMan.Particles do
if particle.ClassName == "MOSRotating" then
<insert supplementary checks here>
mosr = ToMOSRotating(particle);
mosr:GibThis();
end
end


Thu Nov 26, 2009 4:41 am
Profile
User avatar

Joined: Fri Dec 28, 2007 4:19 am
Posts: 1119
Reply with quote
Post Re: Mouse position?
Hrm funky, no errors, but I'm trying to get this to gib pretty much any object that's a subclass of MOSRotatings, so far its doing nothing.

Code:
function Create(self)
   local curdist = 33;
   for particle in MovableMan.Particles do
   local avgx = particle.Pos.X - self.Pos.X;
   local avgy = particle.Pos.Y - self.Pos.Y;
   local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
   if dist < curdist and (particle.ClassName == "MOSRotating") then
      mosr = ToMOSRotating(particle);
      mosr:GibThis();
   end
    end
end

function Update(self)
   local curdist = 33;
   for particle in MovableMan.Particles do
   local avgx = particle.Pos.X - self.Pos.X;
   local avgy = particle.Pos.Y - self.Pos.Y;
   local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
   if dist < curdist and (particle.ClassName == "MOSRotating") then
      mosr = ToMOSRotating(particle);
      mosr:GibThis();
   end
    end
end


Thu Nov 26, 2009 4:50 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 15 posts ] 

Who is online

Users browsing this forum: No registered users


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.046s | 13 Queries | GZIP : Off ]