Data Realms Fan Forums http://45.55.195.193/ |
|
Mouse position? http://45.55.195.193/viewtopic.php?f=73&t=17162 |
Page 1 of 1 |
Author: | DSMK2 [ Thu Nov 19, 2009 4:54 pm ] |
Post subject: | 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. |
Author: | CaveCricket48 [ Thu Nov 19, 2009 11:39 pm ] |
Post subject: | Re: Mouse position? |
Quote: How do I get mouse position? Something sort of finding the point where the sharp aim dots are. Quote: As well, how do I get forward vectors of an object? Quote: And playing sounds via lua. |
Author: | DSMK2 [ Thu Nov 19, 2009 11:47 pm ] |
Post subject: | 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. |
Author: | CaveCricket48 [ Fri Nov 20, 2009 1:02 am ] |
Post subject: | Re: Mouse position? |
Code: object.Vel = Vector(pointB.X-pointA.X,pointB.Y-pointA.Y):SetMagnitude(#); Replace # with the speed you want. |
Author: | DSMK2 [ Fri Nov 20, 2009 2:17 am ] |
Post subject: | 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... |
Author: | CaveCricket48 [ Fri Nov 20, 2009 2:29 am ] |
Post subject: | 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 |
Author: | DSMK2 [ Fri Nov 20, 2009 4:16 am ] |
Post subject: | Re: Mouse position? |
Alright works, but why not ObstacleRay? Just wondering. |
Author: | CaveCricket48 [ Fri Nov 20, 2009 11:25 pm ] |
Post subject: | 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. |
Author: | DSMK2 [ Fri Nov 20, 2009 11:56 pm ] |
Post subject: | 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... |
Author: | CaveCricket48 [ Sat Nov 21, 2009 12:08 am ] |
Post subject: | Re: Mouse position? |
Yes, MORays would work too. Be sure to set the "material ID to ignore" to 0. |
Author: | DSMK2 [ Thu Nov 26, 2009 2:07 am ] |
Post subject: | Re: Mouse position? |
Working on another lua based weapon now, what's the property name for MOSRotatings in the moveable manager? |
Author: | Grif [ Thu Nov 26, 2009 3:09 am ] |
Post subject: | Re: Mouse position? |
MovableMan.Particles, and then check for if particle.ClassName == "MOSRotating" |
Author: | DSMK2 [ Thu Nov 26, 2009 4:40 am ] |
Post subject: | Re: Mouse position? |
What if I want to run a function like GibThis(); How does type casting happen in lua? |
Author: | Grif [ Thu Nov 26, 2009 4:41 am ] |
Post subject: | 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 |
Author: | DSMK2 [ Thu Nov 26, 2009 4:50 am ] |
Post subject: | 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 |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |