A few more scripting issues

Post » Mon Nov 19, 2012 7:36 am

The first one is just me being bad at trigonometry. I'm trying to get the object in an alias to continuously translate to a spot about two feet in front of the player. Unfortunately, it kind of goes crazy and skitters around, and bashes into me a lot moving me around rather than just going where I want it and staying there.
Second problem is, I need the thing to shoot towards an actor and THEN deal damage. Unfortunately, it seems to deal damage before translating to the actor. So, that's not good. Here's the script, hopefully you guys can show me the error of my ways.

Scriptname PCKP_Script_GravThrownAlias extends ReferenceAlias GlobalVariable Property ShouldThrow autoReferenceAlias Property HitActor autoActor Property PlayerREF autoint DealDamage=0event OnTranslationComplete()float Heading = PlayerRef.GetHeadingAngle(GetReference())if ShouldThrow.GetValue() as int==1  ;GetReference().SplineTranslateToRefNode(PlayerRef, "NPC R Hand [RHnd]", 1, 1024)  while ShouldThrow.GetValue() as int==1   ;if GetReference().GetDistance(PlayerREF) >= 128    GetReference().SplineTranslateTo(PlayerRef.GetPositionX() +- (20*Math.asin(Heading)),PlayerRef.GetPositionY() +- (20*(Math.acos(Heading))), PlayerRef.GetPositionZ() +90, 0, 0, 0, 1, 1280)   ;else   ; Utility.Wait(0.05)   ;endIf  endWhile elseIf HitActor.GetReference() && DealDamage==0   GetReference().SplineTranslateToRefNode(HitActor.GetReference(), "NPC Head [Head]", 1, 1280)  while GetReference().GetDistance(HitActor.GetReference()) > HitActor.GetReference().GetHeight()   Utility.Wait(0.05)  endWhile  DealDamage=1 elseIf  DealDamage==1  GetReference().SetMotionType(GetReference().Motion_Dynamic)  float DamageDealt = (GetReference().GetMass() * 5.0)  if (GetReference().GetBaseObject() as Weapon) || (GetReference().GetBaseObject() as Ammo)   DamageDealt = DamageDealt * 2.0  endIf  Debug.Notification(DamageDealt)  (HitActor.GetReference() as Actor).DamageActorValue("Health", DamageDealt)  HitActor.Clear()   Clear()else  GetReference().SetMotionType(GetReference().Motion_Dynamic)  HitActor.Clear()  Clear()endIfendEvent

The first if statement is a bit counter-intuitive, as 1 means DON'T throw the object. It's where I want stuff in front of me. Where dealdamage==0 I want the thing to fly at the hit actor, which works about 30% of the time. The rest of the time the thing just falls to the ground, but still deals damage. This implies that the translation function should be happening, but just isn't. Maybe I need a better while condition for testing if the translation to the actor has occurred yet. I dunno.

Thanks in advance,
Alex
User avatar
Javier Borjas
 
Posts: 3392
Joined: Tue Nov 13, 2007 6:34 pm

Post » Mon Nov 19, 2012 6:49 am

bumper cars
User avatar
sarah
 
Posts: 3430
Joined: Wed Jul 05, 2006 1:53 pm

Post » Sun Nov 18, 2012 10:32 pm

Well, I don't know if this is exactly what you're looking for, but this will move an object directly in front of the actor. I found it somewhere else, but I don't really remember where, so I can't give credit. Sorry.
MoveTo( someactor, distance*Math.Sin(someactor.GetAngleZ()), distance*Math.Cos(someactor.GetAngleZ()), whateverheightyouwant )

Edit2: I'll post an image of why that works, in case you don't get how to apply it to your situation:
http://i.imgur.com/hMvbC.jpg

Okay, the other thing is that you're using splinetranslateto... I'm pretty sure the "spline" is made from the direction the object is facing when you call it. So if the object is facing the opposite direction from which it will move, I think it's going to look weird no matter what. I'm not certain though, because I've never used the function, that's just waht I got from the wiki article.

This is what I mean, or how I think it works:
http://i.imgur.com/4MvEU.jpg

If that's the case, don't ask me how to rotate the object in the right direction first... I have no idea.

Edit: The reason I think that is because there's a "afTangentMagnitude" parameter, but no way to specify the tangent angles, and obviously it's not supposed to use a straight line because that would be pointless, so I'm guessing it would use the rotation of the object.
User avatar
Ashley Clifft
 
Posts: 3468
Joined: Thu Jul 26, 2007 5:56 am

Post » Mon Nov 19, 2012 3:05 am

I don't care much about rotation, so I'm fine there. Thanks for the reply, I'll try it out.
EDIT: I fixed the rest of the kinks myself. Thanks for all your help guys!
User avatar
dav
 
Posts: 3338
Joined: Mon Jul 30, 2007 3:46 pm


Return to V - Skyrim