Sign in to follow this  

Projectiles don't aim for the mouse.

This topic is 1952 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to make it so that whenever this createProjectile function is called the projectile will move tward the mouse.

It does for the most part but it is always a little off.

here is the function
private void createProjectile()
{
if (projectiles.Count < projectiles.Capacity)
{
Texture2D tempTex = (Texture2D)Globals.globalTextures["projectile"];
MouseState state = Mouse.GetState();
Vector2 mDirection = new Vector2(state.X - position.X , state.Y - position.Y);
mDirection.Normalize();
projectiles.Add(new Projectile(tempTex, new Vector2(position.X + (this.textureImage.Width / 2), position.Y + (this.textureImage.Height / 2)), new Point(tempTex.Width, tempTex.Height), 0, new Point(0, 0), new Point(0, 0), new Vector2(300, 300), 1, mDirection, ProjectileType.EnergyBall, 1000, true));
}
}

The position vector is the position of the sprite that is creating the projectile.

thanks in advance,
Ben

Share this post


Link to post
Share on other sites
[quote]
It does for the most part but it is always a little off.
[/quote]

[s]Elaborate on the meaning of a little off.[/s]

[s]Is the position vector a float and mouse state an int?
Is this c#?[/s] Edit: XNA

I don't see any immediate problem here, can you describe what is a little off?

The only thing I see is this:
new Vector2(position.X + (this.textureImage.Width / 2), position.Y + (this.textureImage.Height / 2))

Is this suppose to pass a value of the center point for the texture or the top left? IDK Edited by Neometron

Share this post


Link to post
Share on other sites

This topic is 1952 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

Sign in to follow this