Detecting Collision with Translateto functions

Post » Wed Jun 20, 2012 10:24 am

Has anyone a working example of using translateTo functions while detecting collision? I have a couple ideas about how to do it, but maybe there is something easier I'm missing.

* Spawns an activator that turns to the desired direction and casts a spell that spawns an item with an explosion after colliding with something. Will this work with any surface or roof?

* Throws an object with Havok, register it for update and detect the change in movement vectors. I would have to match the distance traveled with the force applied for this one.


The idea is having a spell that enhances the player jumping skills, and while it kinda works outside, going through walls is hardly a feature...hehe. Here is the script now in case anyone is curious.

Spoiler
Scriptname ShanaJumpingMEffect2Script extends activemagiceffect; ---------- Properties; ---------- VariablesActor targetActorFloat JumpingHeight = 150.0Float JumpingSpeed = 200.0Float JumpingDirectionalMultiplier = 3.0Float OldXFloat OldYFloat NewXFloat NewYFloat VecX = 0.0Float VecY = 0.0Event OnEffectStart(Actor Target, Actor Caster)	Debug.Trace("	OnEffectStart")	targetActor = Target		if ( ! RegisterForAnimationEvent(targetActor, "JumpUp") )		Debug.Trace("	cannot register JumpUp")	endif		OldX = targetActor.GetPositionX()	OldY = targetActor.GetPositionY()	RegisterForUpdate(0.2)	EndEventEvent OnUpdate()	NewX = targetActor.GetPositionX()	NewY = targetActor.GetPositionY()	VecX = JumpingDirectionalMultiplier * ( NewX - OldX )	VecY = JumpingDirectionalMultiplier * ( NewY - OldY )	OldX = NewX	OldY = NewY		Debug.Trace(" VecX , VecY : " + VecX + " , " + VecY )EndEventEvent OnAnimationEvent(ObjectReference akSource, string asEventName)	Debug.Trace("	OnAnimationEvent asEventName: " + asEventName)	if (asEventName == "JumpUp")		if ( VecX != 0 || VecY !=0 )			akSource.TranslateTo(akSource.GetPositionX() + VecX, akSource.GetPositionY() + VecY, akSource.GetPositionZ() + JumpingHeight, 0, 0, 0, 4*JumpingSpeed)		else			akSource.TranslateTo(akSource.GetPositionX() + VecX, akSource.GetPositionY() + VecY, akSource.GetPositionZ() + JumpingHeight, 0, 0, 0, JumpingSpeed)		endif	endifEndEventEvent OnTranslationAlmostComplete()	Debug.Trace("	OnTranslationAlmostComplete")	targetActor.StopTranslation()EndEventEvent OnEffectFinish(Actor Target, Actor Caster)	Debug.Trace("	OnEffectFinish")	UnregisterForAnimationEvent(targetActor, "JumpUp") ; This always returns a runtime error...EndEvent

A side effect of this approach is that when the jumping animation ends and you are ending the translation somehow sometimes player's controls are enabled to cast spells and use weapons lol.
User avatar
kyle pinchen
 
Posts: 3475
Joined: Thu May 17, 2007 9:01 pm

Post » Tue Jun 19, 2012 11:35 pm

Something to consider here, would be to enclose the player in a transparent box mesh with moving collision (maybe an orizontal plane with moving collision, like a lied down door could do also the trick), being said mesh the one using the translate command instead of the player. The box will will drag the player and once it reach an obstacle, it will pass through it, but the player won't. You can then enclose the player again the next time the improved jump is used.
User avatar
Flutterby
 
Posts: 3379
Joined: Mon Sep 25, 2006 11:28 am

Post » Wed Jun 20, 2012 1:40 pm

Both of your options work.

1) The first one will look like you are on a zip line. You'll go sttraight from where you are to where it hit. It'll work on an (solid) surface/object/npc.

2) Throwing the havok object and then translating to it also works. I'm currently troubleshooting it to set up flying.

Your issue is going to be update speed; if it's too slow then your player will not follow the curved Havoc path, but a blocker version. Worse case you havoc-throw your target over a wall, update after it lands, and then get translate-clipped through the wall.
User avatar
CHANONE
 
Posts: 3377
Joined: Fri Mar 30, 2007 10:04 am

Post » Wed Jun 20, 2012 1:34 am

Something to consider here, would be to enclose the player in a transparent box mesh with moving collision (maybe an orizontal plane with moving collision, like a lied down door could do also the trick), being said mesh the one using the translate command instead of the player. The box will will drag the player and once it reach an obstacle, it will pass through it, but the player won't. You can then enclose the player again the next time the improved jump is used.

Creating a collision box sounds good. But I am still not sure how we would move it, since I assume using translateTo on it would make it skip all Havok behaviour itself. Maybe something else that could be tried with your approach is detecting when the box stops being in LOS, but since the player's camera can move or not be oriented to the direction of the translation, I am neither sure it would work...

Both of your options work.

1) The first one will look like you are on a zip line. You'll go sttraight from where you are to where it hit. It'll work on an (solid) surface/object/npc.

2) Throwing the havok object and then translating to it also works. I'm currently troubleshooting it to set up flying.

Your issue is going to be update speed; if it's too slow then your player will not follow the curved Havoc path, but a blocker version. Worse case you havoc-throw your target over a wall, update after it lands, and then get translate-clipped through the wall.

At first I thought the zip line would not matter in the first case. Then I realized that if I only use one TranslateTo call, I fall like a rock after the peak, so I guess I should use another one to fake the inertia of the jump...The only thing that makes me lazy about it, is that I am going to have to work with angles so the spell is casted in the direction of the peak or of the landing point... grrrr :biggrin:

As for the second, shouldn't just use ApplyHavokImpulse do it? After reading your worst case scenario, I am also wondering if the size of the havok object collision box matters also...

Thanks for your answers, I think I am going to try to get the spell approach working at least for standing jumps and see what happens :)
User avatar
Christie Mitchell
 
Posts: 3389
Joined: Mon Nov 27, 2006 10:44 pm


Return to V - Skyrim