Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added strikeObject lightning feature #1938

Merged
merged 2 commits into from
Feb 5, 2017

Conversation

John3
Copy link
Contributor

@John3 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 added strikeObject feature added strikeObject lightning feature Feb 1, 2017
@Areloch
Copy link
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
Copy link
Contributor Author

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
Copy link

dottools commented Feb 1, 2017

This PR also has tabs vs spaces indention conflict issue.

@RichardsGameStudio
Copy link
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);
	   }
   }
}

@John3
Copy link
Contributor Author

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 add_strikeObject branch February 5, 2017 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants