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



Reply to topic  [ 10 posts ] 
 rotate projectile dependent on the way the actor faces 
Author Message
User avatar

Joined: Fri Oct 16, 2009 7:45 pm
Posts: 72
Reply with quote
Post 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.


Mon Nov 02, 2009 4:56 pm
Profile
User avatar

Joined: Tue Dec 12, 2006 3:10 pm
Posts: 495
Location: Uncertain quantum state
Reply with quote
Post 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.


Mon Nov 02, 2009 4:59 pm
Profile
DRL Developer
DRL Developer

Joined: Fri May 15, 2009 10:29 am
Posts: 4107
Location: Russia
Reply with quote
Post 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.


Mon Nov 02, 2009 5:01 pm
Profile
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post 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.


Mon Nov 02, 2009 5:55 pm
Profile
User avatar

Joined: Fri Oct 16, 2009 7:45 pm
Posts: 72
Reply with quote
Post 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


Mon Nov 02, 2009 6:11 pm
Profile
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post 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


Mon Nov 02, 2009 6:20 pm
Profile
User avatar

Joined: Fri Oct 16, 2009 7:45 pm
Posts: 72
Reply with quote
Post 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
Mon Nov 02, 2009 7:24 pm
Profile
User avatar

Joined: Tue Dec 12, 2006 3:10 pm
Posts: 495
Location: Uncertain quantum state
Reply with quote
Post 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.


Mon Nov 02, 2009 8:09 pm
Profile
User avatar

Joined: Fri Oct 16, 2009 7:45 pm
Posts: 72
Reply with quote
Post 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


Mon Nov 02, 2009 9:51 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post 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


Tue Nov 03, 2009 12:21 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 10 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.158s | 14 Queries | GZIP : Off ]