Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

[SOLVED] Cannot set IProjectile.Position when it is ProjectileItem.GRENADE_LAUNCHER

Did you encounter a problem, exploit, glitch or bug while playing the game or running the dedicated server software? Tell us about it here.
Forum rules
By using the forum you agree to the following rules. For this forum you also need to follow these additional rules.
Post Reply
NearHuscarl
Superfighter
Superfighter
Posts: 97
Joined: Thu Feb 07, 2019 4:36 am

[SOLVED] Cannot set IProjectile.Position when it is ProjectileItem.GRENADE_LAUNCHER

Post by NearHuscarl » Thu Mar 26, 2020 10:41 am

The grenade launcher projectile keep falling although I set it to the same position in the update loop

Code to reproduce

Code: Select all

private static IProjectile m_projectile;

public void OnStartup()
{
	var me = Game.GetPlayers()[0];
	me.GiveWeaponItem(WeaponItem.GRENADE_LAUNCHER);

	Events.ProjectileCreatedCallback.Start((ps) =>
	{
		foreach (var p in ps)
		{
			if (p.ProjectileItem == ProjectileItem.GRENADE_LAUNCHER)
			{
				m_projectile = p;
				break;
			}
		}
	});

	Events.UpdateCallback.Start((e) =>
	{
		if (m_projectile == null) return;
		m_projectile.Position = Vector2.Zero; // set to any empty space position depend on your map
		m_projectile.Velocity = Vector2.Zero;
		Game.WriteToConsole(m_projectile.Position);
	});
}
EDIT: thanks to Ebomb09 on discord, I managed to solve this problem. Turn out it's just a quirk in the ScriptAPI. If you want to make the GrenadeLauncher projectile hover in the air. Simply set its velocity to Velocity(0, 100) as stated in IProjectile.Velocity's document

Code: Select all

	Gets or Sets the current velocity that the projectile covers each second. Note: Sync over server-client assumes the velocity stays intact and changing this each update can make it look janky on clients. Note: You can not set a velocity greater than the max speed of the projectile and not set a velocity less than 100 in magnitude.
I assume that the 100 is to offset the gravity force. Because grenades motion are affected by gravity
1 x
Image

Post Reply