Custom ItemAbility Help

AwesomePossum

New member
So I'm pretty lost how to do this. My ideal vision for this is to have the characters have an innate ability to use a Grappling Hook that will pull them to wherever it hits and align their gravity to the impact area, but I'm not sure if that would be possible.

What I've been trying to do in the meantime is give the character's weapons a secondary use that fires an arrow with a gravity zone attached, and then teleport the character to it, but even that isn't working as I thought it would? It seems to only sometimes fire the custom MagicArrow I made, and when I tried to add a delay to the teleport action, it didn't seem to teleport anymore a all. Also it will only trigger if you aim at the ground, so I'm unsure what I need to do, as the documentation doesn't seem to mention too much of this. I was hoping I'd at least be able to make it teleport to the impact location of the arrow, if I couldn't make it pull the character there (and be able to be interrupted by damage), but the Impact Event doesn't have a Teleport function? Would I be able to copy the current Teleport OnCast into the OnImpact area or something along those lines?

And also I'm wondering if there's a way to only have the Indicator only show up while the button is held, and then the ability used on release? I'm guessing I'll probably need to dive into some code for that as well, but I don't know where to look.

The custom MagicArrow I cuurrently have just has a different gravity flip thing added since I couldn't find a prefab for a box collider gravity zone, but I remembered the Demo had one on the moving platforms, so I think I'll be able to look at that for help there. Never mind, the platforms just use the AlignToGround to adjust the gravity, I think? But I think I can figure out how to use the Abstract Gravity Zone for a Box Collider one, maybe, haha.
 
Last edited:
Your idea of firing a projectile with a GravityZone attached sounds like a good one.

The Teleport cast action validates the target position in IsValidTargetPosition, within which it checks if the target position is on the floor (within the character's slope limit). So you'd need to at least have a custom cast action (you can just inherit from Teleport) and change that logic within IsValidTargetPosition (e.g. you could just return true). Although to be honest in your case I'm not sure if using the Teleport cast action is the best option, since you want it to be based on the position of a fired projectile. I would instead use the Spawn Projectile cast action to fire a MagicProjectile, then in MagicProjectile.OnCollision you can do the teleport manually using UltimateCharacterLocomotion.SetPositionAndRotation (which is exactly how the Teleport cast action does it anyway).

The surface indicator's visibility is determined in MagicItem.LateUpdate. Since LateUpdate is not overrideable, you may want instead to add a custom script to the actual surface indicator gameobject, which would listen to input press/release and set itself as visible/invisible accordingly. You could just directly modify the logic in LateUpdate, but if you do be sure to put some kind of tags around it in the code, so that if you ever update UCC you know what changes you've made and can copy them over in case the update overrides MagicItem.
 
Thanks a ton, I've now got it teleporting to the projectile when it impacts, and only showing the indicator while holding the button!

I am having some issues with the GravityZone, though... I must be doing something wrong with it since the other example is a sphere. Mine currently has a point beyond it that I thought I could make the new "down" direction, and it kind of does, but it then just always tries to pull you to that spot (pretty much just the center of a sphere still). With another controller I messed around with a bit, you could set the new "up" direction based on the transform, but I couldn't get that transferred to this correctly.
I think it might be easier for me to keep "Align to Ground" on and set the rotation so it's facing the way the projectile is sticking out, so then it will align to that surface, is that correct? Or is there something simple I'm missing to just set a new direction for gravity with the GravityZone?

And lastly, if I were to try and make the projectile pull you to it's location instead of teleporting you, is there something included in UFPS that could do something along those lines, or would I have to replace the teleport code with something to move the gameObject directly. I feel like maybe it would work if I passed the point to a coroutine that would cancel if you took damage? But I feel like I'd probably create lots more problems, so maybe I'll stick to teleporting for now, haha. Though maybe it's better to break everything before I get too far in. :p
 
Yeah, the spherical gravity zones are intended for spherical shapes, like the planets in the demo scene. Align To Ground is definitely the thing you want when you've got a certain gravity direction you want to maintain.

There are probably a few different ways you could do that. The Move Towards ability is one option, although to be honest I'm not sure how well it would play with moving the character to an arbitrary position in the air since I believe it just uses pathfinding. Another option is to use AbilityMotor - this is not really explained in the docs, but UltimateCharacterLocomotion has the AbilityMotor variable, which will add to the character's motor throttle every frame, i.e. allows you to add any arbitrary force to the character. So you could have an ability that sets the AbilityMotor value to an appropriate value based on the direction & distance that the character needs to travel. A third option would be to manually move the character using SetPosition, which would be the most straightforward solution but also the most likely to produce bugs or complications as you predicted.
 
Top