Sign in to follow this  

[Solved] Isometric Rock Throwing

This topic is 3772 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

OK, my problem is I need to throw rocks in isometric view. Sounds easy enough, just do motion on an inclined plane, but it's not. This is what I have so far (C#) in my player class: /// <summary> /// The player attacks... /// </summary> private void Attack() { Vector2 throwVector = Vector2.Zero; switch (facing) { case Direction.SouthEast: throwVector = new Vector2((float)(Math.Cos(MathHelper.ToRadians(300))), (float)(Math.Sin(MathHelper.ToRadians(300)))); break; case Direction.NorthEast: throwVector = new Vector2((float)(Math.Cos(MathHelper.ToRadians(30))), -(float)(Math.Sin(MathHelper.ToRadians(30)))); break; case Direction.NorthWest: throwVector = new Vector2((float)(Math.Cos(MathHelper.ToRadians(120))), -(float)(Math.Sin(MathHelper.ToRadians(120)))); break; case Direction.SouthWest: throwVector = new Vector2((float)(Math.Cos(MathHelper.ToRadians(210))), -(float)(Math.Sin(MathHelper.ToRadians(210)))); break; default: break; } //code normally creates a new projectile here! } And in the projectile class: switch (facing) { case Direction.SouthEast: gravityVector = new Vector2((float)(Math.Cos(MathHelper.ToRadians(210))), (float)(Math.Sin(MathHelper.ToRadians(210)))) * gravity; break; case Direction.NorthEast: gravityVector = new Vector2((float)(Math.Cos(MathHelper.ToRadians(300))), (float)(Math.Sin(MathHelper.ToRadians(300)))) * gravity; break; case Direction.NorthWest: gravityVector = new Vector2((float)(Math.Cos(MathHelper.ToRadians(210))), (float)(Math.Sin(MathHelper.ToRadians(210)))) * gravity; break; case Direction.SouthWest: gravityVector = new Vector2((float)(Math.Cos(MathHelper.ToRadians(300))), (float)(Math.Sin(MathHelper.ToRadians(300)))) * gravity; break; default: break; } For calculating which direction gravity is. This is quite hard as I've already tried several different techniques and so far this one works most accurately. If anyone can help with determining when it hits the isometric ground also, that would be much appreciated. [Edited by - NickHighIQ on August 14, 2007 8:46:07 PM]

Share this post


Link to post
Share on other sites
Don't work with 2D coordinates only here: you're throwing a rock up, so you need to keep track of it's height. That should make things a lot easier to do.

And a note on your code: every time you update your projectiles position, you create a new gravity Vector2. Why not reuse the old one?

Share this post


Link to post
Share on other sites
I'm not sure what your problem is. Are you having difficulty getting the rock to hit where you think it should, or are you having difficulty determining where to show the rock onscreen during flight, or is there some other problem?

Share this post


Link to post
Share on other sites
Quote:
Original post by Captain P
Don't work with 2D coordinates only here: you're throwing a rock up, so you need to keep track of it's height. That should make things a lot easier to do.

And a note on your code: every time you update your projectiles position, you create a new gravity Vector2. Why not reuse the old one?


Quoted for emphasis. There's no such thing as "throwing rocks in isometric view"; you can draw them in isometric view, but objects are thrown in the world space. First make sure you can "throw" them without rendering (i.e. just print out the rock's x,y,z coordinates each frame), and handle the rendering by transforming its world position into a screen position.

You might also want to try asking here.

Share this post


Link to post
Share on other sites
I figured it out guys. What I did was, for the rock's 'real velocity' (i.e. it's velocity vector) I just had a velocity vector that moved it across the ground. I then had another separate floating point variable holding its height and height-velocity. I add gravity to the latter value each frame and subsequently added height-velocity to height. Then, when rendering, I just translated it directly up the screen by the height.

I know this isn't 100% accurate but I don't want to have to use 3D maths and it looks good enough for me :) Thanks for the replies, that's what lead me to the solution.

Share this post


Link to post
Share on other sites
Quote:
Original post by NickHighIQ
I know this isn't 100% accurate but I don't want to have to use 3D maths and it looks good enough for me :) Thanks for the replies, that's what lead me to the solution.

Actually, it is 100% accurate. Well, virtually so, neglecting only minutiae such as air resistance and coriolis effect :D

Share this post


Link to post
Share on other sites

This topic is 3772 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