Detecting an object's collision

Post » Sun Jan 02, 2011 6:20 pm

Ok... Basically what I want to do is detect if an object has struck something else (anything else really). As far as I know there aren't any functions for that, but I want it to try out something. The game obviously knows if things hit each other, I just can't think of a way to access that. OBSE doesn't have a function for it as far as I know...

Any ideas?
User avatar
Cesar Gomez
 
Posts: 3344
Joined: Thu Aug 02, 2007 11:06 am

Post » Sun Jan 02, 2011 9:48 am

I thought there was an onHit function? That may only apply to the player attacking though.

I haven't scripted in sooo long :3

gl finding the answer =d
User avatar
Ella Loapaga
 
Posts: 3376
Joined: Fri Mar 09, 2007 2:45 pm

Post » Sun Jan 02, 2011 3:26 am

I found a work-around.

The results:

http://www.youtube.com/watch?v=XN5zP3-shK8
http://www.youtube.com/watch?v=IKbBQoiSVgg
http://www.youtube.com/watch?v=4wsgUSoIMyU
User avatar
WTW
 
Posts: 3313
Joined: Wed May 30, 2007 7:48 pm

Post » Sun Jan 02, 2011 9:08 am

Pray do share how you achieved that. :)
User avatar
Tina Tupou
 
Posts: 3487
Joined: Fri Mar 09, 2007 4:37 pm

Post » Sun Jan 02, 2011 11:50 am

Well, this script is not exactly cleaned up yet, but this is what I used to do it:

Spoiler
scn AATPLGlassItemSCRIPTfloat xPosfloat yPosfloat zPosfloat xPosOldfloat yPosOldfloat zPosOldfloat xDifffloat yDifffloat zDiffshort doOnceshort movingFastXshort movingFastYshort movingFastZref glassRefref myRefbegin GameMode	if GetDisabled		return	endif	if doOnce == 0		set doOnce to 1		set xPos to GetPos x		set yPos to GetPos y		set zPos to GetPos z		set xPosOld to xPos		set yPosOld to yPos		set zPosOld to zPos		set myRef to GetSelf	endif	set xPos to GetPos x	set yPos to GetPos y	set zPos to GetPos z	if IsControlPressed 28 == 0		set xDiff to xPos - xPosOld		set yDiff to yPos - yPosOld		set zDiff to zPos - zPosOld		if xDiff < 0			set xDiff to 0 - xDiff		endif		if yDiff < 0			set yDiff to 0 - yDiff		endif		if zDiff < 0			set zDiff to 0 - zDiff		endif		if movingFastX			if xDiff < 1				set glassRef to PlaceAtMe AATPLStatueNoctGlassBroken1 1				glassRef.SetAngle X 50				glassRef.SetAngle Y 45				glassRef.SetAngle Z 143				set glassRef to PlaceAtMe AATPLStatueNoctGlassBroken2 1 0 30				glassRef.SetAngle X 120				glassRef.SetAngle Y 14				glassRef.SetAngle Z -153				Disable			endif		elseif movingFastY			if yDiff < 1				set glassRef to PlaceAtMe AATPLStatueNoctGlassBroken1 1				glassRef.SetAngle X 50				glassRef.SetAngle Y 45				glassRef.SetAngle Z 143				set glassRef to PlaceAtMe AATPLStatueNoctGlassBroken2 1 0 30				glassRef.SetAngle X 120				glassRef.SetAngle Y 14				glassRef.SetAngle Z -153				Disable			endif		elseif movingFastZ			if zDiff < 1				set glassRef to PlaceAtMe AATPLStatueNoctGlassBroken1 1				glassRef.SetAngle X 50				glassRef.SetAngle Y 45				glassRef.SetAngle Z 143				set glassRef to PlaceAtMe AATPLStatueNoctGlassBroken2 1 0 30				glassRef.SetAngle X 120				glassRef.SetAngle Y 14				glassRef.SetAngle Z -153				Disable			endif		endif		if xDiff > 3			set movingFastX to 1		else			set movingFastX to 0		endif		if yDiff > 3			set movingFastY to 1		else			set movingFastY to 0		endif		if zDiff > 3			set movingFastZ to 1		else			set movingFastZ to 0		endif	else		set movingFastX to 0		set movingFastY to 0		set movingFastZ to 0	endif	set xPosOld to xPos	set yPosOld to yPos	set zPosOld to zPosend


Basically, it keeps track of the object's movement speed and if it goes fast (which needs to be worked out a bit more mathematically than checking if it is greater than "3") and then goes really slow the next frame, it must have hit something. So I replace it with the broken parts. I also make sure the player is not moving things around at the time, as that is the only way I can make sure the player isn't just moving it around in the air that I can think of. I could fix most of the issues with it if I could work out how to detect if it actually collides with something though. So if anyone gets any ideas for that, let me know.
User avatar
Princess Johnson
 
Posts: 3435
Joined: Wed Feb 07, 2007 5:44 pm

Post » Sun Jan 02, 2011 4:44 am

My script has now been updated to only happen when an actual collision occurs.

Spoiler
scn AATPLGlassStatueSCRIPTfloat xPosfloat yPosfloat zPosfloat xPosOldfloat yPosOldfloat zPosOldfloat xDifffloat yDifffloat zDifffloat fastSpeedfloat slowSpeedshort doOncefloat movingFastTimerref glassRefref myRefbegin OnAdd	set doOnce to 1	set xPos to GetPos x	set yPos to GetPos y	set zPos to GetPos z	set xPosOld to xPos	set yPosOld to yPos	set zPosOld to zPos	set myRef to GetSelfendbegin OnDrop	set doOnce to 1	set xPos to GetPos x	set yPos to GetPos y	set zPos to GetPos z	set xPosOld to xPos	set yPosOld to yPos	set zPosOld to zPos	set myRef to GetSelfendbegin GameMode	if GetDisabled		return	endif	if doOnce == 0		set doOnce to 1		set xPos to GetPos x		set yPos to GetPos y		set zPos to GetPos z		set xPosOld to xPos		set yPosOld to yPos		set zPosOld to zPos		set myRef to GetSelf	endif	set movingFastTimer to movingFastTimer - GetSecondsPassed	set xPos to GetPos x	set yPos to GetPos y	set zPos to GetPos z	if IsControlPressed 28 == 0		set xDiff to xPos - xPosOld		set yDiff to yPos - yPosOld		set zDiff to zPos - zPosOld		if xDiff < 0			set xDiff to 0 - xDiff		endif		if yDiff < 0			set yDiff to 0 - yDiff		endif		if zDiff < 0			set zDiff to 0 - zDiff		endif		set slowSpeed to 1 * GetSecondsPassed		if myRef.GetSoundPlaying "CGlass*" 50			if movingFastTimer > 0				set glassRef to PlaceAtMe AATPLGlassStatueBrokenTop 1				glassRef.SetAngle X 50				glassRef.SetAngle Y 45				glassRef.SetAngle Z 143				set glassRef to PlaceAtMe AATPLGlassStatueBrokenBottom 1 0 30				glassRef.SetAngle X 120				glassRef.SetAngle Y 14				glassRef.SetAngle Z -153				Disable			endif		endif		set fastSpeed to 50 * GetSecondsPassed		if xDiff > fastSpeed			set movingFastTimer to 0.1		endif		if yDiff > fastSpeed			set movingFastTimer to 0.1		endif		if zDiff > fastSpeed			set movingFastTimer to 0.1		endif	endif	set xPosOld to xPos	set yPosOld to yPos	set zPosOld to zPosend


If anyone in the future wants to see if any further updates are made, they will probably be in my thread in the Mod forum (to save me posting in both): http://www.gamesas.com/index.php?/topic/1155069-poc-breakable-glass-statue/
User avatar
neen
 
Posts: 3517
Joined: Sun Nov 26, 2006 1:19 pm

Post » Sun Jan 02, 2011 6:05 am

PlaceAtMe is not a good idea, since it create reference that cannot be deleted, and disable only hide it. It can make save file huge.
User avatar
Louise Dennis
 
Posts: 3489
Joined: Fri Mar 02, 2007 9:23 pm

Post » Sun Jan 02, 2011 9:04 am

PlaceAtMe is not a good idea, since it create reference that cannot be deleted, and disable only hide it. It can make save file huge.


This only creates two objects, which will not cause savegame bloat. It is only when placeatme is called over and over that it becomes a problem. In those cases it can still be managed however (i use it a lot in my Serpent Isle remake, but delete every reference so that the save game does not grow huge)
User avatar
DAVId MArtInez
 
Posts: 3410
Joined: Fri Aug 10, 2007 1:16 am

Post » Sun Jan 02, 2011 3:17 pm

Nice! Thanks for sharing :) I remember talking to ShadeMe about that "GetSoundPlaying" trick - nice to be seeing it put to good use! I was trying to detect where a collision should happen, when moving a scripted "projectile" around, and alas, the sound detection only works on things that already have collision data attached to them.

About PlaceAtMe - it is safe to use, even in large quantities as long as you make sure to delete the references. This is impossible for some types, but for items, you can place them in a respawning container, and the game deletes them on reset (which you can trigger) and for creatures, you can move their corpses to a cell that gets reset, whereupon the game deletes them. I used the container version in my "shining creatures" mod. I'm sure Thepal has done one of those in his mod :)
User avatar
Jordyn Youngman
 
Posts: 3396
Joined: Thu Mar 01, 2007 7:54 am

Post » Sun Jan 02, 2011 5:56 pm

Nice! Thanks for sharing :) I remember talking to ShadeMe about that "GetSoundPlaying" trick - nice to be seeing it put to good use! I was trying to detect where a collision should happen, when moving a scripted "projectile" around, and alas, the sound detection only works on things that already have collision data attached to them.

About PlaceAtMe - it is safe to use, even in large quantities as long as you make sure to delete the references. This is impossible for some types, but for items, you can place them in a respawning container, and the game deletes them on reset (which you can trigger) and for creatures, you can move their corpses to a cell that gets reset, whereupon the game deletes them. I used the container version in my "shining creatures" mod. I'm sure Thepal has done one of those in his mod :)


For this i haven't since i don't want the pieces to disappear. For placeatmes in my serpent isle remake i've been using deletereference to remove everything
User avatar
W E I R D
 
Posts: 3496
Joined: Tue Mar 20, 2007 10:08 am


Return to IV - Oblivion