angles_toforward and self.viewangles

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
User avatar
G3mInI
First Lieutenant
Posts: 187
Joined: Sat Jun 29, 2002 3:49 am

angles_toforward and self.viewangles

Post by G3mInI »

I need some understanding on these commands. I want to spawn an effect above and in front of a player depending on where the player is standing. I also want the player to see this effect so I must get the players angles too. I don't understand either command very well. I see it in posts here but don't understand what it is calculating. My objective is to spawn an effect aproximately 80 units in front of the player and 160 units above the players origin. I also, once I learn these commands would like to make it a bit random and spawn the same effect beside the player at same height and behind the player at same height. The effect is dust using animate/fx_dust_fallingfromceiling.tik. As of now I have this which spawns the effect directly above the players head. By the time the effect begins, most of the time the player never sees it.

Code: Select all

local.dust1 = spawn animate/fx_dust_fallingfromceiling.tik angle ( -1 )
local.dust1.origin = local.player.origin + ( 0.00 0.00 160.00 )
local.dust1 anim start
wait 1
local.dust1 remove
Anyone?

G3mInI
lizardkid
Windows Zealot
Posts: 3672
Joined: Fri Mar 19, 2004 7:16 pm
Location: Helena MT

Post by lizardkid »

easy

Code: Select all

local.fx_angles = $player.angle
local.fx_origin = $player.origin + 150 150 50

// do fx
that'd make it fairly far away and about chest height.
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

Post by tltrude »

local.player = parm.other

local.dust1 = spawn animate/fx_dust_fallingfromceiling.tik
local.dust1.angles = local.player.angles
local.dust1.origin = local.player.origin + ( 0 80 160 )
local.dust1 anim start
wait 1
local.dust1 remove

If that does not work, try (80 0 160). By the way, the player's origin is at his feet. So, 160 would be 64 units above his head (160 - 96 = 64).
Tom Trude,

Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

He said he wanted it 80 units in front of the player, not 80 units in the x or y direction :wink:

Try this:
local.dust1.origin = local.player.origin + local.player.forwardvector * 80 + ( 0 0 160 )
Image
User avatar
G3mInI
First Lieutenant
Posts: 187
Joined: Sat Jun 29, 2002 3:49 am

Post by G3mInI »

I can't just use x and y offsets because depending on which way the player is facing x could be behind or to the left or to the right or in front and the same goes with y.

This is what I was looking for as far as in front of the player...

local.dust1.origin = local.player.origin + local.player.forwardvector * 80 + ( 0 0 160 )

Yes tltrude that is what I want. You see my ceilings are all at a height of 160. Or rather my walls in all rooms are 160 and I want the dust to appear to fall from the ceiling.



Now then, how do I calculate the same distance (80 units) to the left, to the right, and behind the player using vectors? Thus I will spawn 4 effects completely surrounding the player all about 80 units away.

G3mInI
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

For the left use local.player.leftvector, for the right use -local.player.leftvector etc :)
Image
User avatar
G3mInI
First Lieutenant
Posts: 187
Joined: Sat Jun 29, 2002 3:49 am

Post by G3mInI »

Ok thanks... and which would be behind backwardvector ?
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

angles_toforward converts angles into a vector that is 1 unit in the direction of the angles . So to place something 80 units in front of the player at the angles he is lookin could you do

$thing.origin = ($player[?].origin + ( angles_toforward ( $player[?].viewangles) * 80))

or maybe get the tag position of the players eyes and use that instead of $player[?].origin ?
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

trigger

Post by tltrude »

I don't see why you don't just spawn, or place, the entities around the origins of the triggers.

By the way, if you need a wood creaking sounds, these works.

aliascache wood_creak1 sound/characters/fs_woodcreak_01.wav soundparms 0.9 0.2 0.9 0.2 160 1600 auto loaded maps "m moh dm obj "
aliascache wood_creak2 sound/characters/fs_woodcreak_04.wav soundparms 0.9 0.2 0.9 0.2 160 1600 auto loaded maps "m moh dm obj "
Tom Trude,

Image
User avatar
G3mInI
First Lieutenant
Posts: 187
Joined: Sat Jun 29, 2002 3:49 am

Post by G3mInI »

Ok the whole purpose of this line of questioning is this. I am trying to recreate the single player experience of the omaha levels. In a server side mod only of obj_objteam3 I have placed a trigger multiple in the bunker areas. If a player is standing inside the bunker anywhere then they will hear the sound of "arty_exp_inside" and their screen will shake. Then .25 seconds later dust falls from the ceiling.

At first I had spawned tons of dust effects all over the ceilings inside the bunker. 97 of them to be exact. I figured there has got to be a better way to do this. Thats when I came up with the thought of spawning the dust in front of the player no matter where he was in the bunker, as long as he was touching my trigger multiple that have spawned.

To be honest what I have now is working great. It is very close to the intensity that the single player omaha beach brings to the player. I have now achieved this for a server side mod multiplayer obj map. I only wanted to spawn a couple of more effects near the player so if the player turned there would be a good chance he would still see some dust falling when the screen shook. As of now I have only tested this with the small detached east bunker. Now all I have to do is gather the proper coordinates for the main or west bunker and spawn 1 or more trigger_multiples with same targetname.


Thread 1 sets up the trigger_multiple in the east bunker.

Code: Select all

bunker_shake_dust_setup:

	//east bunker
	local.bs1 = spawn trigger_multiple origin ( -1136.00 -382.00 272.00 )
	local.bs1 setsize ( -260.00 -418.00 -0.00 ) ( 260.00 418.00 144.00 )
	local.bs1.targetname = bunker_shake_dusty
end

Thread 2 spawns the speaker entities for the interior artillery sound and then detects whether or not the player is touching the trigger. By the way where I have the speaker entities placed, you can only hear the sound when inside the bunker, it does get quieter towards the top but when you are on top outiside you no longer hear it. The entities coordinates are way below the bunkers themselves, one below the east bunker and one below the main or west bunker. The wait 25 statement is in there so that everybody is spawned before any of this starts. I had an issue where if you spawned in the middle a shaking screen your screen would end up crooked when the shaking stopped. By putting in this wait 25, I have pretty much resolved that problem.

Code: Select all

bunker_dust_trigger:

	local.speakerbombs1 = spawn fx/dummy.tik origin ( 1592 672 -624 )
	local.speakerbombs1.targetname = speakerbomb
	local.speakerbombs1 notsolid
	
	local.speakerbombs2 = spawn fx/dummy.tik origin ( -968 -152 -624 )
	local.speakerbombs2.targetname = speakerbomb
	local.speakerbombs2 notsolid

	wait 25

while(1)
	{
	$speakerbomb playsound arty_exp_inside

	local.player = parm.other
	
	if(local.player isTouching $bunker_shake_dusty && Isalive local.player)	
		{
		local.dust1 = spawn animate/fx_dust_fallingfromceiling.tik
		local.dust1.angle = ( -1 )
						
		thread inside_bunker local.player
				
		wait .25
		
		local.dust1.origin = local.player.origin + local.player.forwardvector * 150 + ( 0 0 160 )
				
		local.dust1 anim start
		wait 1
		local.dust1 remove
		}
	wait (randomfloat 1 + 13)
	waitframe
	}

end
Thread 3 controls the players 'shaking' screen

Code: Select all

inside_bunker local.player:

  local.offset = (0 0 0) // make vector 
  for(local.i = 0; local.i <= 2; local.i++) 
    local.offset[local.i] = (randomfloat 2.0 - 1.0) * 5.0 // randnum [-5,5] 
  local.player.viewangles += local.offset // tilt view 
  waitframe 
  wait .08
  if(local.player != NIL && isAlive local.player) 
    local.player.viewangles -= local.offset // reset view 

  local.offset = (0 0 0) // make vector 
  for(local.i = 0; local.i <= 2; local.i++) 
    local.offset[local.i] = (randomfloat 2.0 - 1.0) * 5.0 // randnum [-5,5] 
  local.player.viewangles += local.offset // tilt view 
  waitframe 
  wait .08
  if(local.player != NIL && isAlive local.player) 
    local.player.viewangles -= local.offset // reset view 

  local.offset = (0 0 0) // make vector 
  for(local.i = 0; local.i <= 2; local.i++) 
    local.offset[local.i] = (randomfloat 2.0 - 1.0) * 5.0 // randnum [-5,5] 
  local.player.viewangles += local.offset // tilt view 
  waitframe 
  wait .08
  if(local.player != NIL && isAlive local.player) 
    local.player.viewangles -= local.offset // reset view 

  local.offset = (0 0 0) // make vector 
  for(local.i = 0; local.i <= 2; local.i++) 
    local.offset[local.i] = (randomfloat 2.0 - 1.0) * 5.0 // randnum [-5,5] 
  local.player.viewangles += local.offset // tilt view 
  waitframe 
  wait .08
  if(local.player != NIL && isAlive local.player) 
    local.player.viewangles -= local.offset // reset view 

end

Thats what I have now and by gosh it looks and sounds great. Just maybe another dust spawn behind the player or offset a bit to the left and right and to me it will be perfectamundo! lol


G3mInI
Post Reply