Jump to content
  • Advertisement
Sign in to follow this  
Barkanaxen

Face the mouse[Solved]

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

How would i make an image rotate to always be facing the mouse? using blitz3D. [Edited by - Barkanaxen on October 30, 2007 4:00:35 PM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Barkanaxen
That didnt work, It wasnt what i needed sorry but thank you ToohrVyk for trying
Can you explain why 'atan2' didn't work for you? Did you try it? What were the results? Can you post your code?

Share this post


Link to post
Share on other sites
Well i just went back to it and looked at it a bit harder and tried it but i dont see how i would implememnt this into my code.thats using drawing functions for lines and stuff, i personally cant piece out the part that does what i want.
Thank you

Share this post


Link to post
Share on other sites
Quote:
Original post by Barkanaxen
Well i just went back to it and looked at it a bit harder and tried it but i dont see how i would implememnt this into my code.thats using drawing functions for lines and stuff, i personally cant piece out the part that does what i want.
Thank you
I don't know anything about Blitz3D, but typically you'd do something like this:
Vector2 diff = mouse_position - object_position;
float angle = atan2(diff.y, diff.x);
object_image.render(object_position, angle);

			
		

Share this post


Link to post
Share on other sites
Yea i have been trying different things but i really only understand Blitz and Gamemaker. i can understand but not programm in C. I cant translate that into blitz. well i can i know what it does but how would i do that in blitz coding.lol
Thanks =)

Share this post


Link to post
Share on other sites
Quote:
Original post by Barkanaxen
Yea i have been trying different things but i really only understand Blitz and Gamemaker. i can understand but not programm in C. I cant translate that into blitz. well i can i know what it does but how would i do that in blitz coding.lol
Thanks =)



Quote:

Vector2 diff = mouse_position - object_position;

float angle = atan2(diff.y, diff.x);

object_image.render(object_position, angle);


Maybe I can translate it into some English and then maybe you could understand it.

Basicaly that is taking a difference vector, and it is assigning it to the difference between mouse_position-object_position. That is pretty self explanatory of what those variables mean and represent. They are both vectors though.

Next comes the angle at which something is. The y and the x points are what is plugged into the function.

Next might be what could take a little bit. That is just rendering the object you want (hence the object_image [that's the object you want rendered] instance) to the objects position (hence the object_position vector), at the angle you presented it. Blitz3D may not have a function to draw things and takes an angle. If it does then there you go.

If you don't understand what vectors are, then I suggest you just do a quick Google search and study up on them. Pretty important when it comes to game programming.


I hope this helps at least some what!

Chad

Share this post


Link to post
Share on other sites
I think i can get it now man, Thank u for taking the time to help. I respect that =). Along with everyone else who tried as well =). Thanks everyone!

Share this post


Link to post
Share on other sites
Here is my problem now, I have all that set up and completely understand it but What i have to do to rotate it is create a strip for rotation like with a certain amount of frames. well i made one with 36 frames. i load it into the game and here is what i typed

"PlayerIMG=LoadAnimImage("Images/actors/PlayerROT.BMP",34,34,0,36)"
loads the strip with 36 frames that are 34 by 34 pixels. and starting at frame 0.

"
diffx=mousex-Player.Actor\x
diffy=mousey-Player.Actor\y
dir=ATan2(diffy,diffx)
Player.Actor\direction=dir
"
Blitz 3d version of what waas shown to me.

"
drawimage Player.Actor\image,Player.Actor\x,Player.Actor\y,Player.Actor\direction
"
wich draws the image at its x and y in that direction. well the thing is the direction isnt supposed to be an angle. It needs to be a frame number but atan2 gives u negative numbers and numbers that are higher than 36. so if anyone understands this then please help. It would be much appreciated.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!