Data Realms Fan Forums http://45.55.195.193/ |
|
My Raycast won't rotate. http://45.55.195.193/viewtopic.php?f=73&t=24566 |
Page 1 of 1 |
Author: | Coops [ Wed Jul 13, 2011 8:01 pm ] |
Post subject: | 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. |
Author: | TheLastBanana [ Wed Jul 13, 2011 8:41 pm ] |
Post subject: | 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? |
Author: | Coops [ Wed Jul 13, 2011 8:50 pm ] |
Post subject: | 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. |
Author: | TheLastBanana [ Wed Jul 13, 2011 10:03 pm ] |
Post subject: | 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 |
Author: | zoidberg [ Wed Jul 13, 2011 10:03 pm ] |
Post subject: | 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. |
Author: | Coops [ Thu Jul 14, 2011 12:43 am ] |
Post subject: | Re: My Raycast won't rotate. |
Works like a charm now, thanks TLB. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |