View unanswered posts | View active topics It is currently Wed Jun 26, 2019 5:33 am



Reply to topic  [ 6 posts ] 
 My Raycast won't rotate. 
Author Message
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post My Raycast won't rotate.
So I've been playing around with this thing for 2 nights now and I can't figure out whats keeping it from what it needs to do.

From what I can tell with certain debugging tools is that the Ray Cast doesn't go anywhere but to the right (Default, I think) when it should be following a certain target. The first self.guidePixel goes in the right direction but the second self.guidepixel2 doesn't.

Anyhow, here's the script, It's all in the function update and it's a homing device that checks if any obstacles are in the way, if there is then a new path is given, but I haven't gotten that far yet. If I did anything wrong, this would be the first time of it acting up.

Code:
   if self.LifeTimer:IsPastSimMS(250) then
      for actor in MovableMan.Actors do
         local dist = SceneMan:ShortestDistance(self.Pos,actor.Pos,true).Magnitude
         if dist < 1250 and actor.Team ~= self.Team then
            self.target = actor
            break
         else
            self.RotAngle = SceneMan:ShortestDistance(self.Pos,(self.parentActor.Pos + Vector((SceneMan.SceneWidth/2),SceneMan.SceneHeight)),true).AbsRadAngle
         end
      end
   end
   if MovableMan:IsActor(self.target) then
      self.target:FlashWhite(100) -- Debuging
      local pointHit = Vector()
      local pointMiss = Vector()
      local angleAim = SceneMan:ShortestDistance(self.Pos, self.target.Pos, true).AbsRadAngle
      self.guidePixel = CreateMOPixel("SAW.rte/Small Effect") -- Debuging
      self.guidePixel.Pos = self.Pos + Vector(40,0):RadRotate(angleAim) -- Debuging
      MovableMan:AddParticle(self.guidePixel) -- Debuging
      local pathCheck = Vector():RadRotate(angleAim)
      local hitCheck = SceneMan:CastObstacleRay(self.Pos, pathCheck, pointHit, pointMiss, self.ID, -1, 0)
      print(pointHit) -- Debuging
      if hitCheck == 0 or SceneMan:ShortestDistance(pointHit, self.target.Pos, true).Magnitude > 3 then
         self.guidePixel2 = CreateMOPixel("SAW.rte/Small Effect") -- Debuging
         self.guidePixel2.Pos = pointMiss + Vector(0,-45) -- Debuging
         MovableMan:AddParticle(self.guidePixel2) -- Debuging
         print("Found Obstacle!") -- Debuging
      end
   end


Thanks.


Wed Jul 13, 2011 8:01 pm
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3134
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: My Raycast won't rotate.
The reason is that, by default, Vector() creates a vector of (0,0). (0,0) rotated by any amount is still (0,0). Why not just use SceneMan:ShortestDistance as your vector to trace along?


Wed Jul 13, 2011 8:41 pm
Profile WWW
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: My Raycast won't rotate.
That doesn't make sense though, Ive used a default Vector of (0,0) before and it worked fine.

Not only that but I am using ShortestDistance as the vector to trace along.


Wed Jul 13, 2011 8:50 pm
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3134
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: My Raycast won't rotate.
No, you're over-complicating things. You're getting SceneMan:ShortestDistance (a vector), turning that into an angle, creating another vector, rotating that vector according to the angle you got from SceneMan:ShortestDistance, then using that. It's way easier to just straight-up use SceneMan:ShortestDistance:
Code:
   if self.LifeTimer:IsPastSimMS(250) then
      for actor in MovableMan.Actors do
         local dist = SceneMan:ShortestDistance(self.Pos,actor.Pos,true).Magnitude
         if dist < 1250 and actor.Team ~= self.Team then
            self.target = actor
            break
         else
            self.RotAngle = SceneMan:ShortestDistance(self.Pos,(self.parentActor.Pos + Vector((SceneMan.SceneWidth/2),SceneMan.SceneHeight)),true).AbsRadAngle
         end
      end
   end
   if MovableMan:IsActor(self.target) then
      self.target:FlashWhite(100) -- Debuging
      local pointHit = Vector()
      local pointMiss = Vector()
      local shortestDist = SceneMan:ShortestDistance(self.Pos, self.target.Pos, true)
      local hitCheck = SceneMan:CastObstacleRay(self.Pos, shortestDist, pointHit, pointMiss, self.ID, -1, 0)
      print(pointHit) -- Debuging
      if hitCheck == 0 or SceneMan:ShortestDistance(pointHit, self.target.Pos, true).Magnitude > 3 then
         self.guidePixel2 = CreateMOPixel("SAW.rte/Small Effect") -- Debuging
         self.guidePixel2.Pos = pointMiss + Vector(0,-45) -- Debuging
         MovableMan:AddParticle(self.guidePixel2) -- Debuging
         print("Found Obstacle!") -- Debuging
      end
   end


Wed Jul 13, 2011 10:03 pm
Profile WWW

Joined: Fri Feb 25, 2011 3:52 pm
Posts: 39
Reply with quote
Post Re: My Raycast won't rotate.
Quote:
That doesn't make sense though, Ive used a default Vector of (0,0) before and it worked fine.

i don't believe you, it's a bit impossible.

i'm sure that i used Vector(1, 0) for rotating and magnituding, and it worked fine.


Wed Jul 13, 2011 10:03 pm
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: My Raycast won't rotate.
Works like a charm now, thanks TLB.


Thu Jul 14, 2011 12:43 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.016s | 13 Queries | GZIP : Off ]