added strikeObject lightning feature #1938

Merged
merged 2 commits into from Feb 5, 2017

Conversation

Projects
None yet
4 participants
@John3
Contributor

John3 commented Feb 1, 2017

added new feature strikeObject to lightning.

Now you can throw a lightning to objects derived from shapebase, like players, Items, AI, etc.

EDIT: typo

@John3 John3 changed the title from added strikeObject feature to added strikeObject lightning feature Feb 1, 2017

@Areloch Areloch added the Improvement label Feb 1, 2017

@Areloch

This comment has been minimized.

Show comment
Hide comment
@Areloch

Areloch Feb 1, 2017

Contributor

Noted 2 things with this:

  1. I hadn't initially realized strikeObject only works with shapeBase. I tried passing in a static before and it crashed. We should probably make it either SceneObject, or if we really do only want ShapeBase objects for targets, add a safety check in there if the wrong type is passed in.

  2. The way the strikePoint is passed along is a 0-1 range representing the lighting object's world box, to keep the net events as compact as possible. When you're getting the strike point based on the target object's world transform, the numbers are too big for the expected bit size and it breaks. You'll want to convert the targetObject's world transform to be the local offset of the lighting's world box. That would fix that issue.

If these can get sorted, shouldn't be any issues rolling this in

Contributor

Areloch commented Feb 1, 2017

Noted 2 things with this:

  1. I hadn't initially realized strikeObject only works with shapeBase. I tried passing in a static before and it crashed. We should probably make it either SceneObject, or if we really do only want ShapeBase objects for targets, add a safety check in there if the wrong type is passed in.

  2. The way the strikePoint is passed along is a 0-1 range representing the lighting object's world box, to keep the net events as compact as possible. When you're getting the strike point based on the target object's world transform, the numbers are too big for the expected bit size and it breaks. You'll want to convert the targetObject's world transform to be the local offset of the lighting's world box. That would fix that issue.

If these can get sorted, shouldn't be any issues rolling this in

@John3

This comment has been minimized.

Show comment
Hide comment
@John3

John3 Feb 1, 2017

Contributor

Hey Areloch oops sorry for not added the safety check... Well all ShapeBase objects can receive damage, TSSTatic do not have damage handling, that's why I use ShapeBase. :D :D

I will check the strikepoint to net events. thks

Contributor

John3 commented Feb 1, 2017

Hey Areloch oops sorry for not added the safety check... Well all ShapeBase objects can receive damage, TSSTatic do not have damage handling, that's why I use ShapeBase. :D :D

I will check the strikepoint to net events. thks

@dottools

This comment has been minimized.

Show comment
Hide comment
@dottools

dottools Feb 1, 2017

This PR also has tabs vs spaces indention conflict issue.

dottools commented Feb 1, 2017

This PR also has tabs vs spaces indention conflict issue.

@RichardsGameStudio

This comment has been minimized.

Show comment
Hide comment
@RichardsGameStudio

RichardsGameStudio Feb 3, 2017

Contributor

Thanks for the setup. If you change things like below, everything should work fine and strikepoints should be 0-1.

void Lightning::strikeObject(ShapeBase* targetObj)
{
   AssertFatal(isServerObject(), "Error, client objects may not initiate lightning!");

   Point3F strikePoint = targetObj->getPosition();
   Point3F objectCenter;
   Box3F wb = getWorldBox();
   if (!wb.isContained(strikePoint))
	   return;

   Point3F targetRel = strikePoint - getPosition();
   Point3F length(wb.len_x() / 2.0f, wb.len_y() / 2.0f, wb.len_z() / 2.0f);

   Point3F strikePos = targetRel / length;

   bool playerInWarmup = false;
   Player *playerObj = dynamic_cast< Player * >(targetObj);
   if (playerObj)
   {
	   if (!playerObj->getControllingClient())
	   {
		   playerInWarmup = true;
	   }
   }

   if (!playerInWarmup)
   {
	   applyDamage_callback(targetObj->getWorldSphere().center, VectorF(0.0, 0.0, 1.0), targetObj);
   }

   SimGroup* pClientGroup = Sim::getClientGroup();
   for (SimGroup::iterator itr = pClientGroup->begin(); itr != pClientGroup->end(); itr++) {
	   NetConnection* nc = static_cast<NetConnection*>(*itr);
	   if (nc != NULL)
	   {
		   LightningStrikeEvent* pEvent = new LightningStrikeEvent;
		   pEvent->mLightning = this;

		   pEvent->mStart.x = strikePos.x;
		   pEvent->mStart.y = strikePos.y;
		   pEvent->mTarget = targetObj;

		   nc->postNetEvent(pEvent);
	   }
   }
}
Contributor

RichardsGameStudio commented Feb 3, 2017

Thanks for the setup. If you change things like below, everything should work fine and strikepoints should be 0-1.

void Lightning::strikeObject(ShapeBase* targetObj)
{
   AssertFatal(isServerObject(), "Error, client objects may not initiate lightning!");

   Point3F strikePoint = targetObj->getPosition();
   Point3F objectCenter;
   Box3F wb = getWorldBox();
   if (!wb.isContained(strikePoint))
	   return;

   Point3F targetRel = strikePoint - getPosition();
   Point3F length(wb.len_x() / 2.0f, wb.len_y() / 2.0f, wb.len_z() / 2.0f);

   Point3F strikePos = targetRel / length;

   bool playerInWarmup = false;
   Player *playerObj = dynamic_cast< Player * >(targetObj);
   if (playerObj)
   {
	   if (!playerObj->getControllingClient())
	   {
		   playerInWarmup = true;
	   }
   }

   if (!playerInWarmup)
   {
	   applyDamage_callback(targetObj->getWorldSphere().center, VectorF(0.0, 0.0, 1.0), targetObj);
   }

   SimGroup* pClientGroup = Sim::getClientGroup();
   for (SimGroup::iterator itr = pClientGroup->begin(); itr != pClientGroup->end(); itr++) {
	   NetConnection* nc = static_cast<NetConnection*>(*itr);
	   if (nc != NULL)
	   {
		   LightningStrikeEvent* pEvent = new LightningStrikeEvent;
		   pEvent->mLightning = this;

		   pEvent->mStart.x = strikePos.x;
		   pEvent->mStart.y = strikePos.y;
		   pEvent->mTarget = targetObj;

		   nc->postNetEvent(pEvent);
	   }
   }
}
@John3

This comment has been minimized.

Show comment
Hide comment
@John3

John3 Feb 4, 2017

Contributor

thx richard, I added your suggestion, thax nathan added tab vs space fix.

Contributor

John3 commented Feb 4, 2017

thx richard, I added your suggestion, thax nathan added tab vs space fix.

@Areloch Areloch merged commit 5c8a821 into GarageGames:development Feb 5, 2017

@John3 John3 deleted the John3:add_strikeObject branch Feb 5, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment