Jump to content

(Solved)Projectile Sprite orientation issues


Recommended Posts

I'd hate to be the guy that missed an obvious bit of information, but I've looked for quite a bit and came up with nothing.

My problem is this: The projectile sprite has it's facing oriented so it looks like it is floating flat slightly above the ground. Imagine a piece of card, laying on the floor, and now just raise it up a little.

The only code related to the sprite I've used is " inst.AnimState:SetOrientation(ANIM_ORIENTATION.OnGround)" which allows it to actually 'face' the target it wants to go after, but also makes it suffer from the issue.

Without that bit of code, the projectile remains facing to the right like it does in Spriter. I've looked over various bits of code, and I'm thinking I've done something wrong in spriter, but I'd like secondary input if anyone has it.

:wilson_love:

Link to comment
Share on other sites

11 minutes ago, IronHunter said:

I found a solution here to use the projectile component functions to offset the projectile and increase its hitbox.

 

Huh, I gave that a try. The problem is the same as the one in that post, the projectile is stuck to the ground whereas I actually thought it was still floating. Perspective messed with me.

However, their fix didn't fix it. At least the code they presented didn't. The projectile now spawns in the air, above my character, and slowly falls to the ground as it moves towards the target.

Link to comment
Share on other sites

What I did for one of my projectiles was to spawn a child prefab as a child so the child is offset.
in the masterpostinit of my swordbeam I have this:
 

	inst.fxs = {SpawnPrefab("fx_sword_beam"), SpawnPrefab("cane_victorian_fx")}
	for i,fx in ipairs(inst.fxs) do
		fx.entity:SetParent(inst.entity)--"child prefabs will rotate and move with their parents"
		fx.Transform:SetPosition(0, .75, 0)--"I set my child prefabs to a height of .75, their position is relative to the parent not the world anymore so they'll always appear to be .75 above the parent which handles the hitbox,movement, rotation etc."
	end

My child prefabs do not have any physics so they are not affected by gravity, this is handled by the parent prefab which has inventory physics but lacks a animstate as it doesn't render anything as the graphics is handled by the children.

While my example does create 3 prefabs to do the job of 1, my projectiles are not spawned frequently enough for it to matter that much for performance. You can easily just spawn 1 child in your case and you can do so without needing to store and use a table.

Such as local fx = SpawnPrefab("your_graphic_prefab")

Edited by IronHunter
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

3 hours ago, IronHunter said:

 


	inst.fxs = {SpawnPrefab("fx_sword_beam"), SpawnPrefab("cane_victorian_fx")}
	for i,fx in ipairs(inst.fxs) do
		fx.entity:SetParent(inst.entity)--"child prefabs will rotate and move with their parents"
		fx.Transform:SetPosition(0, .75, 0)--"I set my child prefabs to a height of .75, their position is relative to the parent not the world anymore so they'll always appear to be .75 above the parent which handles the hitbox,movement, rotation etc."
	end

 

I'll take a stab at implementing something like this tomorrow/today when I get the time. This is my first run-in with projectiles in this game and I've fried my brain a couple times already over, what I described as, a 'simple addition'.

If you see this before I do give it a go, any additional advice on how to implement this would be appreciated. I could also send over whatever LUA files you want to see, if you want to see the mess I've made that is.

Link to comment
Share on other sites

1 hour ago, TheAlphaDehur said:

I'll take a stab at implementing something like this tomorrow/today when I get the time. This is my first run-in with projectiles in this game and I've fried my brain a couple times already over, what I described as, a 'simple addition'.

If you see this before I do give it a go, any additional advice on how to implement this would be appreciated. I could also send over whatever LUA files you want to see, if you want to see the mess I've made that is.

I am just going to attach my custom projectile lua file here from my mod.

You can use it as a reference for yours as your projectile probably has different properties like speed, hit detection etc.

zelda_swordbeam.lua

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

11 hours ago, IronHunter said:

I am just going to attach my custom projectile lua file here from my mod.

You can use it as a reference for yours as your projectile probably has different properties like speed, hit detection etc.

zelda_swordbeam.lua 2.17 kB · 1 download

Damn. I wouldn't have asked for one of your LUA's, so I appreciate the file a lot. I'll make use of what few wrinkles my brain has and make this work! Well, hopefully.

:wilson_love:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...