Data Realms Fan Forums
http://45.55.195.193/

rotate projectile dependent on the way the actor faces
http://45.55.195.193/viewtopic.php?f=73&t=17040
Page 1 of 1

Author:  dutchsmoker [ Mon Nov 02, 2009 4:56 pm ]
Post subject:  rotate projectile dependent on the way the actor faces

Some newb lua questions.
I want give the projectile angular velocity but clockwise or counter clockwise depending what side the actor faces.
I.e. when the actor with the gun looks to the left the projectile he just shot will be given self.AngularVel = -10 and self.AngularVel = 10 when facing right while he shot it.
Basicly it's for a gun that shoots a big ball that i want to give angular velocity so it will roll forward , away from the actor , thus i need to know were he's looking at.

Author:  findude [ Mon Nov 02, 2009 4:59 pm ]
Post subject:  Re: rotate projectile dependent on the way the actor faces

When an actor has HFlipped true, they're looking left. Or right. Not entirely sure.
It's HFlipped you want to look at anyways.

Author:  Lizardheim [ Mon Nov 02, 2009 5:01 pm ]
Post subject:  Re: rotate projectile dependent on the way the actor faces

Just make it check the direction it has velocity in then give it rotation in that direction.

Author:  Duh102 [ Mon Nov 02, 2009 5:55 pm ]
Post subject:  Re: rotate projectile dependent on the way the actor faces

findude wrote:
It's HFlipped you want to look at anyways.

This. In the Create function, look for the actor and do
Code:
if actor.HFlipped == true then
   self.AngularVel = -self.AngularVel
end

Then fiddle with the sign of the AngularVel ini the .ini if it's going the other way.

Author:  dutchsmoker [ Mon Nov 02, 2009 6:11 pm ]
Post subject:  Re: rotate projectile dependent on the way the actor faces

oke , so i have to make it get the actor that shoots it , like the homing missle does for checking for team , sorta , then pass that actor onto actor.HFlipped and mod the ini to make the projectile rotate as if the actor was HFlipped = false right ? , i'm familliar with programming just not with lua

Author:  Duh102 [ Mon Nov 02, 2009 6:20 pm ]
Post subject:  Re: rotate projectile dependent on the way the actor faces

Yeah. There's a few different methods of getting the closest actor, there's a thread about Lua snippets here somewhere...
You can use the homing missile one if you want, it's right there.

EDIT: Tricks thread

Author:  dutchsmoker [ Mon Nov 02, 2009 7:24 pm ]
Post subject:  Re: rotate projectile dependent on the way the actor faces

i can't quite get it to work. this is the script i have so far. also it's not getting its mass increased so i think this is a problem with syntax
Code:
function Create(self)
   self.Mass = 500;
--Find out who shot the weapon by finding the closest actor within 50 pixels.
    local curdist = 50;
    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 then
       curdist = dist;
       self.parent = actor;
   end
    end
   if self.parent.HFlipped == true then
      self.AngularVel = -self.AngularVel
end


using code tags is not exaclty perfect , tabs especially so ill add it as attachment

Attachments:
HugeBall.txt [483 Bytes]
Downloaded 144 times

Author:  findude [ Mon Nov 02, 2009 8:09 pm ]
Post subject:  Re: rotate projectile dependent on the way the actor faces

Tabs don't matter for Lua scripts, but they make them human-readable.

You're missing an end at the, well, end of the script.

Author:  dutchsmoker [ Mon Nov 02, 2009 9:51 pm ]
Post subject:  Re: rotate projectile dependent on the way the actor faces

ya , i still need to get used to those end's
actually i ment the way the Code tags show your lua code is not as it is written when i copypasted it.
Quote:
using code tags is not exaclty perfect , tabs especially so ill add it as attachment

Author:  Abdul Alhazred [ Tue Nov 03, 2009 12:21 pm ]
Post subject:  Re: rotate projectile dependent on the way the actor faces

I agree with with Lizard here.
Lizard wrote:
Just make it check the direction it has velocity in then give it rotation in that direction.
Using HFlipped is perfect when spawning objects in an actors code but since you are working with a projectile from a gun using HFlipped just makes things more complicated. Try this instead:

Code:
function Create(self)
   if self.RotAngle > 1.57 or self.RotAngle < -1.57 then   -- the projectile is facing left
      self.AngularVel = 10
   else
      self.AngularVel = -10
   end
end

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/