Results 1 to 7 of 7

Thread: bind/glue to a rotating objet

  1. #1
    Senior Member Ancient Order's Avatar
    Join Date
    Aug 2015
    Location
    Paris, Fr.
    Posts
    256

    Default bind/glue to a rotating objet

    hi there, im trying to bind a trigger to a flakturret but when rotating the turret, the trigger doesn't move, I guess it's bound to the turret origin. Is there a way to bind/glue to the tag_barrel?

  2. #2

    Default Keep an entity 50 units away from another in 3D

    Try this out below, where $flak88 is the flak's targetname.
    There might be a way to check whenever the flak88 is in the middle of firing, that way a trigger could kill any players that are right next to the barrel but didn't get shot.

    Code:
    main:
    	//$flak88 spawned somewhere
    
    	//local.origin = $flak88 gettagposition "tag_barrel"
    
    	local.trigger = spawn trigger_multiple 
    	local.trigger.origin = $flak88.origin //local.origin
    	local.trigger setsize ( -40 -40 -40 ) ( 40 40 40 ) // keep these lower than local.distance = 50
    	local.trigger setthread killem
    	local.trigger thread movetrig
    end
    
    killem:
    
    	local.player = parm.other
    	local.player hurt 9999
    end
    
    movetrig:
    
    	local.distance = 50 // how far away from the flak88's origin
    
    	while($flak88 != NULL)
    	{							// try .viewangles if this doesn't work.
    		local.fwd_vec = angles_toforward $flak88.angles // fwd_vec[2] = 0 when player looks horizontal, -0.999 looking down, 0.999 looking up.
    
    		local.verticaldist = local.fwd_vec[2] * local.distance
    		local.horizontaldist = local.fwd_vec[2]
    
    		if(local.fwd_vec[2] < 0) { local.horizontaldist = local.fwd_vec[2] * -1 } // horizontaldist = 0.999 looking down, 0.999 looking up.
    
    		local.sin = (sin $flak88.angles[1]) * (local.distance - (local.horizontaldist * local.distance)) // when player looks horizontally, horizontal sine and cosine distances are at maximum of 60.
    		local.cos = (cos $flak88.angles[1]) * (local.distance - (local.horizontaldist * local.distance)) // when player looks vertically up or down, horizontal sine and cosine distances are at minimum of 0.
    
    		self.origin = self.origin + ( local.cos local.sin local.verticaldist )
    		waitframe
    	}
    	local.fwd_vec = ( 0 0 0 )
    	self remove
    end
    Last edited by Searingwolfe; April 26th, 2023 at 09:14 AM.

  3. #3
    Senior Member Ancient Order's Avatar
    Join Date
    Aug 2015
    Location
    Paris, Fr.
    Posts
    256

    Default

    Thanks Searingwolfe! I tried something like this but still have problems with the trigger angles to fix (tho it works great when i test with a script_object instead of the trigger) . Anyway i'm looking for something like "attach" just in case it would exist.
    Im trying to set the trigger always paralell to, and of same dimensions as, the flak front armor to make it feel kind of solid and protect the gunner who is actually standing on the shoot slot instead of getting killed thru the notsolid flakturret when shooting
    Code:
    makeBulletHitSound:
    
    	spawn trigger_multipleall spawnflags "128" targetname FlakFakeHull origin ($flak0.origin + ( 0 -50 0 ))
    	$FlakFakeHull.angles = $flak0.angles 
    	$FlakFakeHull setsize ( -70 -2 0 ) ( 70 0 66 )
    
    	while($FlakFakeHull){
    		$FlakFakeHull waittill trigger
                    ...
                    ...
    	}
    
    end
    
    
    calculate_FlakFakeHull_origin:
    
    	spawn static/curtain targetname curtain classname script_object origin ($flak0.origin + ( 0 -50 80 )) angles "0 -90 0" scale "1" 
    	while(1){
    		if($flak0){
    			// x= x0 + r * cos(t) / x0 = abscisse du centre / r = rayon / t = angle en radians
    			// y= y0 + r * sin(t) / y0 = ordonnée du centre / r = rayon / t = angle en radians
    
    			local.x = $flak0.origin[0] + ( 50 * cos($flak0.angles[1] * 3.14159 / 180))
    			local.y = $flak0.origin[1] + ( 50 * sin($flak0.angles[1] * 3.14159 / 180))
    			local.z = $flak0.origin[2]
    			
    			$curtain.origin = ( local.x local.y (local.z + 80))
    			$curtain.angles =  $flak0.angles         <=======this works
    
    			$FlakFakeHull.origin = ( local.x local.y local.z )
    			$FlakFakeHull.angles =  $flak0.angles <=======this doesn't
    			
    			//wait 10
    		}
    		waitframe
    	}
    
    end

  4. #4

    Default

    you can make the player to dont take damage by using the command nodamage on him when he pick the cannon:

    local.player nodamage

  5. #5
    Senior Member Ancient Order's Avatar
    Join Date
    Aug 2015
    Location
    Paris, Fr.
    Posts
    256

    Default

    thanks DK! Yes that's what i planned to do temporarily as soon as a bullet hits the trigger. But i'd like the gunner to keep killable from behind.

  6. #6

    Default Keep an entity 50 units away from another in 3D - Part 2

    Here's my 2nd attempt for keeping an object some distance away from a turret barrel. I forgot in the 1st script to change angles[1] from degrees to radians before running sine and cosine.
    I also needed a way for the turret to know which player is using it ("inuse" and "usingweapon" threads). Thankfully while the player is mounted, he can't trigger any trigger_multiples.

    Run "thread turretgun", change the origin (this was tested on mohdm1), and change the model to a flak88 that can be usable.

    The main problem with making a "bullet shield" trigger that temporarily makes the turret gunner have "nodamage": the very first bullet always hits the player before "nodamage" can run, same with explosions.
    Try this out, the main issue is in the "shot" thread. If you comment out the "takedamage" line, you'll see that players always get hurt after the first triggering.

    Code:
    turretgun:
    
    	local.flak88 = spawn "statweapons/mg42_gun.tik"
    	local.flak88.origin = ( 725 -300 100 )
    	local.flak88.angles = ( 0 0 0 )
    	local.flak88 yawcenter 0
    	local.flak88 pitchcaps ( -135 135 0)
    	local.flak88 setplayerusable 1 
    	local.flak88 setthread inuse 				// called when a player uses the turret
    
    	local.crate = spawn trigger_multiple spawnflags 128 	// respond to bullets, explosions, projectiles, etc
    	local.crate model "static/indycrate.tik"
    	local.crate setsize ( -75 -75 -75 ) ( 75 75 75 ) 	// indycrate dimensions are 71 x 47.
    	local.crate.origin = local.flak88.origin
    	local.crate.angles = local.flak88.angles
    	local.crate show 					// triggers are notsolid and invisible by default
    	local.crate.flak88 = local.flak88
    	local.crate setthread shot
    
    	local.trigger = spawn trigger_multiple
    	local.trigger.origin = local.flak88.origin
    	local.trigger setsize ( -75 -75 -75 ) ( 75 75 75 )
    	local.trigger.flak88 = local.flak88
    	local.trigger setthread usingweapon
    
    	local.crate.flak88 = local.flak88
    	local.crate.originold = local.flak88.origin 		// keep memory of the flak88's initial origin.
    	local.crate thread movetrig
    end
    
    inuse:
    
    	local.player = parm.other
    	self.gunner = local.player // keep memory of who just triggered the turret ("gunner" is not originally from MOHAA, so I had to add one here).
    	waitframe
    	self.gunner.usingweapon = 1
    	self.inuse = 1
    end
    
    usingweapon:
    
    	self nottriggerable
    	local.player = parm.other
    	if(self.flak88 == NULL && (self.flak88.gunner == NIL || self.flak88.gunner == NULL)) { self remove; end }	// if the turret is gone, delete this trigger.
    
    	if(self.flak88.inuse != 1 || self.flak88.gunner.usingweapon != 1) { self triggerable; end }			// if no one is using the turret yet, end.
    
    	if(local.player == self.flak88.gunner) { self.flak88.gunner.usingweapon = 0; self.flak88.inuse = 0; self.flak88.gunner = NIL } // run this only after the player exits the turret
    	self triggerable
    end
    
    shot:
    
    	if(self.flak88.gunner != NIL)
    	{
    		self nottriggerable
    		self.flak88.gunner nodamage					// this does not stop players from dying by explosions
    		waitframe
    		if(self.flak88.gunner != NIL) { self.flak88.gunner takedamage } // the first bullet always hits, before the gunner receives the "nodamage" command.
    		self triggerable
    	}
    end
    
    movetrig:
    
    	local.PI = 3.14159265359 	// MOHAA console may only display first 3 decimals (3.142), but the game does compute beyond 3 decimals.
    	local.distance = 80 		// how far away from the flak88's origin
    
    	while(self.flak88 != NULL)
    	{	
    		if(self.flak88.gunner != NIL) { local.fwd_vec = angles_toforward self.flak88.gunner.viewangles } // fwd_vec[2] = 0 when player looks horizontal, -0.999 looking down, 0.999 looking up.
    		if(self.flak88.gunner == NIL) { local.fwd_vec = angles_toforward self.flak88.angles }
    
    		local.verticaldist = local.fwd_vec[2] * local.distance
    		local.horizontaldist = local.fwd_vec[2]
    
    		if(local.fwd_vec[2] < 0) { local.horizontaldist = local.fwd_vec[2] * -1 } 			// horizontaldist = 0.999 looking down, 0.999 looking up.
    
    		if(self.flak88.gunner != NIL) { local.degrees = self.flak88.gunner.viewangles[1]; self.angles = self.flak88.gunner.viewangles }
    		if(self.flak88.gunner == NIL) { local.degrees = self.flak88.angles[1]; self.angles = self.flak88.angles }
    
    		if(local.degrees >= 180) { local.degrees = local.degrees - 360 } 				// local.player.angles[1] = local.degrees can sometimes be > 180 and < 360.
    		local.radians = local.degrees * (local.PI / 180) 						// for sin/cos to work, degrees must be between -180, 0, 180.
    
    		local.sin = (sin local.radians) * (local.distance - (local.horizontaldist * local.distance))
    		local.cos = (cos local.radians) * (local.distance - (local.horizontaldist * local.distance))
    
    		self.origin = self.originold + ( local.cos local.sin local.verticaldist )
    		waitframe
    	}
    	local.fwd_vec = ( 0 0 0 )
    	self remove
    end
    Last edited by Searingwolfe; May 5th, 2023 at 01:38 PM.

  7. #7
    Senior Member Ancient Order's Avatar
    Join Date
    Aug 2015
    Location
    Paris, Fr.
    Posts
    256

    Default

    Quote Originally Posted by Searingwolfe View Post
    first bullet always hits the player before "nodamage"
    Argh too bad! Thanks a lot for your time anyway!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •