Okay so I know how to rotate a sprite for say a turret toward a object. My problem (with rotating objects that fire projectiles) is offsetting the projectile coming out of a turret (for example) to make it appear as though is coming out of the gun(s). Take these images for example:
I haven't been able to find a good tutorial or work out the math, can someone help me?
P.s I know sometimes I have trouble getting my point across if further explanation is required please let me know.
P.s.s Sorry I posted 2 topics in a short time frame I don't intend to create spam.
Turret Projectile Offset
Moderator: PC Supremacists
- THe Floating Brain
- Chaos Rift Junior
- Posts: 284
- Joined: Tue Dec 28, 2010 7:22 pm
- Current Project: RTS possible Third Person shooter engine.
- Favorite Gaming Platforms: PC, Wii, Xbox 360, GAME CUBE!!!!!!!!!!!!!!!!!!!!!!
- Programming Language of Choice: C/C++, Python 3, C#
- Location: U.S
Turret Projectile Offset
"Why did we say we were going to say we were going to change the world tomorrow yesterday? Maybe you can." - Myself
Re: Turret Projectile Offset
Code: Select all
x = turret.x + cos(turret.direction) * turret.length;
y = turret.y + sin(turret.direction) * turret.length;
For multiple barrels, you can either:
A. use the above code twice - one perpendicular, and one going outwards
B. Use the above code but add a value to the direction to align correctly
C. Use a 2d matrix
Edit:
Since you are likely using a matrix to rotate your sprite, you can use the same one for the offset.
- THe Floating Brain
- Chaos Rift Junior
- Posts: 284
- Joined: Tue Dec 28, 2010 7:22 pm
- Current Project: RTS possible Third Person shooter engine.
- Favorite Gaming Platforms: PC, Wii, Xbox 360, GAME CUBE!!!!!!!!!!!!!!!!!!!!!!
- Programming Language of Choice: C/C++, Python 3, C#
- Location: U.S
Re: Turret Projectile Offset
Thank you so much :-Dbnpph wrote:Something like that for a single barrel.Code: Select all
x = turret.x + cos(turret.direction) * turret.length; y = turret.y + sin(turret.direction) * turret.length;
For multiple barrels, you can either:
A. use the above code twice - one perpendicular, and one going outwards
B. Use the above code but add a value to the direction to align correctly
C. Use a 2d matrix
Edit:
Since you are likely using a matrix to rotate your sprite, you can use the same one for the offset.
"Why did we say we were going to say we were going to change the world tomorrow yesterday? Maybe you can." - Myself
- ibly31
- Chaos Rift Junior
- Posts: 312
- Joined: Thu Feb 19, 2009 8:47 pm
- Current Project: Like... seven different ones
- Favorite Gaming Platforms: Xbox 360, Gamecube
- Programming Language of Choice: C++, ObjC
- Location: New Jersey.
Re: Turret Projectile Offset
I recently had a similar problem except I am using Cocos2D. If whatever library you are using supports a Object to World conversion function you could do this. I specifically did it this way because I needed flexibility for muzzle flashes/lasers and left-to-right motion.
Basically I positioned the bullet at the object->coordinateToWorld( 0.5f, 1.0f ); for the center, and made the bullet travel in the vector direction of the barrels angle.
Basically I positioned the bullet at the object->coordinateToWorld( 0.5f, 1.0f ); for the center, and made the bullet travel in the vector direction of the barrels angle.
Website/Tumblr
My Projects
The best thing about UDP jokes is that I don’t care if you get them or not.