I’m trying to access a function on a script on a different entity in lua but I’m not sure how to do it in lumberyard. Thank you for your help.
I cant seem to figure this out. I’ve been trying to find an answer to this for 3 days. My player needs to update health variable from another script attached to another object. But I’m not sure how to access the script component variables attached to another object. Any help thank you.
Could you explain the exact use that you are trying to accomplish? Is this a shooter or something of that sort?
if you saw my project , you can find your answers, you can use of an empty entity / position x , y , z.
example: x for health value , y for grenade count , z for raycast shoot with Get /Set Posx or Posy or Posz .
you use GetX/EmptyEntity at Player and in AreaTrigger , you use SetX/EmptyEntity.
you must had GetId EmptyEntity.
I implemented this Global Variable Trick in Script Canvas , I’m sure , it is possible also for Lua.
Im looking for the way to access the entity’s script that the raycast hit.
Example: the shoot function attached to the player shooting a racast and getting enamy entity that was shot then decreaseing enamy health in enamy health script attached to enamy entity.
So this isn’t gonna completely help you but maybe you can derive some things going on in my code. I did this to raycast from a VR controller to get entityId’s of what my controller was casting at. It’s derived from the instantVR sample, but can get an entityID using the reflected ‘RayCastConfiguration()’
function raycast:raycastGrab(entityTM, ValidLocationEntity, InvalidLocationEntity, RayLength, UseNavMesh, UseTerrain, controllerEntity) if entityTM ~= nil then local entityPos = entityTM:GetPosition() local rayLength = RayLength local rayDirection = entityTM.basisY local rayPos = nil local rayCollision = true self:HideLocations(ValidLocationEntity, InvalidLocationEntity) local rayCastConfiguration = RayCastConfiguration() rayCastConfiguration.origin = entityPos rayCastConfiguration.direction = rayDirection rayCastConfiguration.maxDistance = rayLength rayCastConfiguration.physicalEntityTypes = 11 -- raycast against all but living entities local rayCastResult = PhysicsSystemRequestBus.Broadcast.RayCast(rayCastConfiguration) if rayCastResult:HasBlockingHit() then topRayCastResult = rayCastResult:GetBlockingHit() Debug.Log("entityId hit: " .. tostring(topRayCastResult['entityId']))
Might not help too much but hopefully it’s a start as long as your projectile doesn’t have travel speed. If it does, you may have to create a separate component to attach to your projectile spawns that track collision (not sure if you can get entityId’s of collided this way, have not tried).
Is it possible in lumberyard?
I found the Solution Using :gameplayNotificationBus https://forums.awsgametech.com/t/tutorial-communicating-between-lua-scripts-in-lumberyard-1-8/2528/1
you should work with events instead of direct reference.