Jump to content
The Dark Mod Forums

Setting vector angles to player view on a projectile


kingsal

Recommended Posts

Hello!

Is it possible to set the direction of a projectile's model to match that of the player view?

This is an inventory item similar to a mine, but it flies out in the direction of the player view.

 

This is the script I am using (copied from the mine)

void playertools_sporebomb::inventoryUseKeyRelease(entity userEntity, entity eFrobbed, float holdTime){	entity projectile = sys.spawn(getKey("def_projectile"));		vector viewAngles = $player1.getViewAngles();	vector direction = sys.angToForward(viewAngles);	vector velocity = direction;	velocity *= getVelocityFactorForHoldTime(holdTime);	vector origin = $player1.getEyePos();	origin += direction * 30;	projectile.setOrigin(origin);	string soundShader = projectile.getKey("snd_throw");	sys.cacheSoundShader(soundShader);	// If the soundchannel argument is empty, the float defaults to 0, which is SND_CHANNEL_ANY	projectile.startSoundShader(soundShader, SND_CHANNEL_BODY);	// Callback to decrease the inventory stack count	$player1.changeInvItemCount(getKey("inv_name"), getKey("inv_category"), -1);	projectile.launch( origin, direction, velocity );	// Clear the projectile's CONTENT_PROJECTILE flag so that it doesn't collide with the player in the first few hundred msec.	float savedClipMask = projectile.getClipMask();	projectile.setClipMask(PROJECTILE_LAUNCH_CLIPMASK);	// Reset the clipmask back to normal after a certain amount of time	sys.wait(projectile.getFloatKey("delay"));	projectile.setClipMask(savedClipMask);}

And the def I am using for the projectile.

entityDef projectile_sporebomb{	"inherit"		    		"atdm:projectile_base"	"spawnclass"				"idProjectile"	"editor_displayFolder"		        "playertools/base/projectiles"		"fire_along_playerview"		        "1"			"bindOnImpact"				"0"	"model" 		    		"models/darkmod/weapons/sporebomb.ASE"	"mins"       				"-1 -1 -2"	"maxs"       				"1 1 0"	"cone"       				"3"		//"def_damage"				"damage_wineBottle"		"has_result"				"1"	"def_result"				"result_sporebomb"	"active_surfaces"			""	        //"angles"            		        "0 0 0" //This was the culprit. Setting the angles to 0 0 0 was over-riding the code that orients the projectile to the player view. 	//"axial_dir"			        "0 0 0"	//"launchFromBarrel"			"1"	"health"				"5"						"velocity"				"10 0 0"	"angular_velocity"			"0 0 0"				"thrust"				"0"				"thrust_start"				"0"						"thrust_end"				"0"						"linear_friction"			"0"	"angular_friction"			"0"	"contact_friction"			"0"	"bounce"				"0"		"mass"					"20"	"gravity"				"10"					"fuse"					"5"			"detonate_on_fuse"			"1"						"detonate_on_death"			"1"						"detonate_on_world"			"1"						"detonate_on_actor"			"1"						"impact_damage_effect"		        "1"						"impact_gib"				"0"							"snd_fly"					""	"snd_throw"					"gasbomb_flight" //TEMP	"snd_drop"					""	}
Edited by kingsal
  • Like 1
Link to comment
Share on other sites

Update:

 

I found a solution by removing the "angles" from my .def file. This was over-riding the projectile code that orients the model to the player's view vector.

It would still be interesting to see what the code would look like in a script however..

  • Like 2
Link to comment
Share on other sites

Check the script files for the player tools includded in the mod. There you can see how it is done.

FM's: Builder Roads, Old Habits, Old Habits Rebuild

Mapping and Scripting: Apples and Peaches

Sculptris Models and Tutorials: Obsttortes Models

My wiki articles: Obstipedia

Texture Blending in DR: DR ASE Blend Exporter

Link to comment
Share on other sites

Hmm, I'll take a look in there and see what I can dig out.

 

Is there anyway to cap the maximum velocity on a projectile but still factor in a hold time? I know you can set some global variables that will change the hold time velocity factor, but that seems to break a lot of stuff.

 

This is the projectile script I am looking at:

 

I've set a max_velocity key, I'm just not sure how to say always make getVelocityFactorForHoldTime(holdTime) <= max_velocity.

void playertools_sporebomb::inventoryUseKeyRelease(entity userEntity, entity eFrobbed, float holdTime)
{
		
	
	entity projectile = sys.spawn(getKey("def_projectile"));
	
	//The following lines do bad things.
	//HOLD_TIME_MIN_VELOCITY = projectile.getFloatKey("hold_time_min_velocity");
	//HOLD_TIME_MAX_VELOCITY = projectile.getFloatKey("hold_time_max_velocity");							
	//MIN_VELOCITY = projectile.getFloatKey("min_velocity");
	//MAX_VELOCITY = projectile.getFloatKey("max_velocity");	
	
	float max_velocity = projectile.getFloatKey("max_velocity");
	
	vector viewAngles = $player1.getViewAngles();
	vector direction = sys.angToForward(viewAngles);

	vector velocity = direction;
	velocity *= getVelocityFactorForHoldTime(holdTime);

	vector origin = $player1.getEyePos();
	origin += direction * 30;
	projectile.setOrigin(origin);
	
	
	string soundShader = projectile.getKey("snd_throw");
	sys.cacheSoundShader(soundShader);

	// If the soundchannel argument is empty, the float defaults to 0, which is SND_CHANNEL_ANY
	projectile.startSoundShader(soundShader, SND_CHANNEL_BODY);

	// Callback to decrease the inventory stack count
	$player1.changeInvItemCount(getKey("inv_name"), getKey("inv_category"), -1);

	projectile.launch( origin, direction, velocity );

	// Clear the projectile's CONTENT_PROJECTILE flag so that it doesn't collide with the player in the first few hundred msec.
	float savedClipMask = projectile.getClipMask();
	projectile.setClipMask(PROJECTILE_LAUNCH_CLIPMASK);

	// Reset the clipmask back to normal after a certain amount of time
	sys.wait(projectile.getFloatKey("delay"));
	projectile.setClipMask(savedClipMask);
}
Edited by kingsal
  • Like 1
Link to comment
Share on other sites

Those values are defined in tdm_playertools.script

 

#define HOLD_TIME_MIN_VELOCITY 200        // The minimum hold time (a threshold)
#define HOLD_TIME_MAX_VELOCITY 1200        // The maximum hold time to achieve MAX_VELOCITY
#define MIN_VELOCITY 0                    // The velocity for holdTime <= HOLD_TIME_MIN_VELOCITY
#define MAX_VELOCITY 900                // The velocity for holdTime > HOLD_TIME_MAX_VELOCITY

and used later on here

 

/**
* greebo: This returns the velocity factor for a given hold time.
*          the factor is clamped to MIN_VELOCITY and MAX_VELOCITY.
*          Below the threshold HOLD_TIME_MIN_VELOCITY, the factor is MIN_VELOCITY.
*          Above HOLD_TIME_MAX_VELOCITY the factor is MAX_VELOCITY.
*          Between those two values, the factor is interpolated.
*/
float getVelocityFactorForHoldTime(float holdTime) {
    float velocityFactor;
    
    if (holdTime > HOLD_TIME_MIN_VELOCITY) {
        velocityFactor = (holdTime - HOLD_TIME_MIN_VELOCITY) / (HOLD_TIME_MAX_VELOCITY - HOLD_TIME_MIN_VELOCITY);
        velocityFactor *= MAX_VELOCITY;
    }
    else {
        velocityFactor = MIN_VELOCITY;
    }

    return velocityFactor;
}

If you don't want to use that values, I would suggest that you write your own version of that function and use that instead.

 

So the beginning of your script could look like this

 

// change these values as you want them. you can use shorter names of course, but make sure they aren't already used.
#define HOLD_TIME_MIN_VELOCITY_CUSTOM 200        // The minimum hold time (a threshold)
#define HOLD_TIME_MAX_VELOCITY_CUSTOM 1200        // The maximum hold time to achieve MAX_VELOCITY
#define MIN_VELOCITY_CUSTOM 0                    // The velocity for holdTime <= HOLD_TIME_MIN_VELOCITY
#define MAX_VELOCITY_CUSTOM 900                // The velocity for holdTime > HOLD_TIME_MAX_VELOCITY
// again the naming can be different
float getVelocityFactorForHoldTimeCustom(float holdTime) {
    float velocityFactor;
    
    if (holdTime > HOLD_TIME_MIN_VELOCITY_CUSTOM) {
        velocityFactor = (holdTime - HOLD_TIME_MIN_VELOCITY_CUSTOM) / (HOLD_TIME_MAX_VELOCITY_CUSTOM - HOLD_TIME_MIN_VELOCITY_CUSTOM);
        velocityFactor *= MAX_VELOCITY_CUSTOM;
    }
    else {
        velocityFactor = MIN_VELOCITY_CUSTOM;
    }

    return velocityFactor;
}
  • Like 1

FM's: Builder Roads, Old Habits, Old Habits Rebuild

Mapping and Scripting: Apples and Peaches

Sculptris Models and Tutorials: Obsttortes Models

My wiki articles: Obstipedia

Texture Blending in DR: DR ASE Blend Exporter

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recent Status Updates

    • OrbWeaver

      Does anyone actually use the Normalise button in the Surface inspector? Even after looking at the code I'm not quite sure what it's for.
      · 4 replies
    • Ansome

      Turns out my 15th anniversary mission idea has already been done once or twice before! I've been beaten to the punch once again, but I suppose that's to be expected when there's over 170 FMs out there, eh? I'm not complaining though, I love learning new tricks and taking inspiration from past FMs. Best of luck on your own fan missions!
      · 4 replies
    • The Black Arrow

      I wanna play Doom 3, but fhDoom has much better features than dhewm3, yet fhDoom is old, outdated and probably not supported. Damn!
      Makes me think that TDM engine for Doom 3 itself would actually be perfect.
      · 6 replies
    • Petike the Taffer

      Maybe a bit of advice ? In the FM series I'm preparing, the two main characters have the given names Toby and Agnes (it's the protagonist and deuteragonist, respectively), I've been toying with the idea of giving them family names as well, since many of the FM series have named protagonists who have surnames. Toby's from a family who were usually farriers, though he eventually wound up working as a cobbler (this serves as a daylight "front" for his night time thieving). Would it make sense if the man's popularly accepted family name was Farrier ? It's an existing, though less common English surname, and it directly refers to the profession practiced by his relatives. Your suggestions ?
      · 9 replies
    • nbohr1more

      Looks like the "Reverse April Fools" releases were too well hidden. Darkfate still hasn't acknowledge all the new releases. Did you play any of the new April Fools missions?
      · 5 replies
×
×
  • Create New...