Author |
Message |
dutchsmoker
Joined: Fri Oct 16, 2009 7:45 pm Posts: 72
|
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 |
|
|
findude
Joined: Tue Dec 12, 2006 3:10 pm Posts: 495 Location: Uncertain quantum state
|
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 |
|
|
Lizardheim
DRL Developer
Joined: Fri May 15, 2009 10:29 am Posts: 4107 Location: Russia
|
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 |
|
|
Duh102
happy carebear mom
Joined: Tue Mar 04, 2008 1:40 am Posts: 7096 Location: b8bbd5
|
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 |
|
|
dutchsmoker
Joined: Fri Oct 16, 2009 7:45 pm Posts: 72
|
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 |
|
|
Duh102
happy carebear mom
Joined: Tue Mar 04, 2008 1:40 am Posts: 7096 Location: b8bbd5
|
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 |
|
|
dutchsmoker
Joined: Fri Oct 16, 2009 7:45 pm Posts: 72
|
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
|
Mon Nov 02, 2009 7:24 pm |
|
|
findude
Joined: Tue Dec 12, 2006 3:10 pm Posts: 495 Location: Uncertain quantum state
|
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 |
|
|
dutchsmoker
Joined: Fri Oct 16, 2009 7:45 pm Posts: 72
|
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 |
|
|
Abdul Alhazred
DRL Developer
Joined: Tue Aug 11, 2009 5:09 am Posts: 395
|
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 |
|
|
|