Jump to content


Photo

Stationary Rotation of player objects.


  • Please log in to reply
12 replies to this topic

#1 _257168

_257168

    GMC Member

  • New Member
  • 8 posts

Posted 12 March 2012 - 07:58 PM

So i am working on a project for class for a elective course, I am making a game sort of a mix between asteroids and space invaders. What i am needing to do but not being able to figure out is how to make a stationary player controlled object with the left and right keys. That Rotates 360 and is able to shoot in the direction it is facing. Been sifting through pages of google searches and these forums and have yet to find a solution to this. Thanks for your time and i will probably continue to use this topic to finish this project.


To add to this i could also use a good guide on making menu screens. I am wanting to make a start menu (simple) as well as a end game/credits screen.

Edited by _257168, 12 March 2012 - 08:04 PM.

  • 0

#2 Jakyl11

Jakyl11

    GMC Member

  • GMC Member
  • 3109 posts
  • Version:GM:Studio

Posted 12 March 2012 - 08:06 PM

if you have pro version you can use image_angle

left key
image_angle+=10;//10 is rotation speed

right key
image_angle-=10;

then to shoot

bullet=instance_create(x,y,obj_bullet);//assign a temp variable to the created object
bullet.direction=image_angle;//set its direction to image angle of object creating it
bullet.speed=10;//set the speed for the bullet
bullet.image_angle=image_angle;//set the angle of the bullets sprite
//etc...

now if you dont have pro it takes quite a bit more to code

Edited by Jakyl11, 12 March 2012 - 08:06 PM.

  • 0

#3 _257168

_257168

    GMC Member

  • New Member
  • 8 posts

Posted 12 March 2012 - 08:15 PM

if you have pro version you can use image_angle

left key

image_angle+=10;//10 is rotation speed

right key
image_angle-=10;

then to shoot

bullet=instance_create(x,y,obj_bullet);//assign a temp variable to the created object
bullet.direction=image_angle;//set its direction to image angle of object creating it
bullet.speed=10;//set the speed for the bullet
bullet.image_angle=image_angle;//set the angle of the bullets sprite
//etc...

now if you dont have pro it takes quite a bit more to code


Sadly i am using the lite version since it was just a one term class, We really only got a light over view of the program making a few basic games ( Space invaders clone, Solomons Key clone, Pong clones.. Using mostly only game makers built in functions, Then for our final we are set loose on choosing and attempting to make our own game. Corse i seem to have bitten off more then i can chew as far as trying to make a function work :P Got everything else figured out except this part.


Edit: Going to work (will be slow to reply but will continue to do so)

Edited by _257168, 12 March 2012 - 08:25 PM.

  • 0

#4 goldage5

goldage5

    GMC Member

  • GMC Member
  • 152 posts

Posted 12 March 2012 - 08:25 PM

do you need an animation for the object?

if you dont, you can take a right facing version of the sprite, and add a rotation sequence (counter-clockwise, 360 degrees in 360 frames)

then, where you use image_angle in Jakyl11's post, replace it with image_index.
  • 0

#5 _257168

_257168

    GMC Member

  • New Member
  • 8 posts

Posted 12 March 2012 - 08:33 PM

do you need an animation for the object?

if you dont, you can take a right facing version of the sprite, and add a rotation sequence (counter-clockwise, 360 degrees in 360 frames)

then, where you use image_angle in Jakyl11's post, replace it with image_index.


The object does not need any special animation, I used the image edit to make it have a counter clockwise rotation in 360 frames so i have that. Just not sure how to implement the rotation.

Edited by _257168, 13 March 2012 - 06:10 PM.

  • 0

#6 _257168

_257168

    GMC Member

  • New Member
  • 8 posts

Posted 13 March 2012 - 06:10 PM

Picked up the full version of GameMaker, This should make things go smoother.

Well i am still unable to get my image to rotate, i have the 360 degree sprite. Have added the line there to turn it but i don't seem to understand how to implement the turning. I am useing Press left combined with transform sprite.

Edited by _257168, 13 March 2012 - 06:27 PM.

  • 0

#7 _163997

_163997

    GMC Member

  • New Member
  • 35 posts

Posted 13 March 2012 - 06:50 PM

Put the code Jakyl11 suggested in the events you want ie KEY PRESS LEFT event for first code, KEY PRESS RIGHT for second code, and MOUSE LEFT PRESSED for the bullet creation.

If you want a constant rotation while the key is held down then use KEYBOARD LEFT or RIGHT respectively.

Edited by _163997, 13 March 2012 - 07:01 PM.

  • 0

#8 _257168

_257168

    GMC Member

  • New Member
  • 8 posts

Posted 13 March 2012 - 07:10 PM

Sweet, I got it (had not used game maker with direct code before) Thought hat looked a lot like small basic script :P The problem i am having now with the sprite is that its in a constant counter clockwise rotation. But i do have control over the ship. (mind the fact its endlessly turning counter clockwise.)
  • 0

#9 _163997

_163997

    GMC Member

  • New Member
  • 35 posts

Posted 13 March 2012 - 07:14 PM

Sweet, I got it (had not used game maker with direct code before) Thought hat looked a lot like small basic script :P The problem i am having now with the sprite is that its in a constant counter clockwise rotation. But i do have control over the ship. (mind the fact its endlessly turning counter clockwise.)


What event did you put the code in? The Step event?
If so remove that code and put all of the code below in its place.

//rotates counter clockwise when left is pressed
if keyboard_check(vk_left)
    {
    image_angle+=10;
    }
    
//rotates clockwise when right is pressed
if keyboard_check(vk_right)
    {
    image_angle-=10;
    }

Edited by _163997, 13 March 2012 - 07:18 PM.

  • 0

#10 _257168

_257168

    GMC Member

  • New Member
  • 8 posts

Posted 13 March 2012 - 07:32 PM

Wow! i got it i love you guys! My ship now turns in place... Shoots in direction its facing :)
  • 0

#11 _163997

_163997

    GMC Member

  • New Member
  • 35 posts

Posted 13 March 2012 - 07:45 PM

Woo hoo, that was my first contribution to this site! I usually hassle people - it's good to give something back. If you have any other questions just holler.

One little thing to consider, is the bullet object being created at the centre of your ship sprite or at the tip of your ship?

Edited by _163997, 13 March 2012 - 07:46 PM.

  • 0

#12 _257168

_257168

    GMC Member

  • New Member
  • 8 posts

Posted 13 March 2012 - 07:53 PM

Woo hoo, that was my first contribution to this site! I usually hassle people - it's good to give something back. If you have any other questions just holler.

One little thing to consider, is the bullet object being created at the centre of your ship sprite or at the tip of your ship?


The bullet is coming from the center, But the sprite i chose for the ship makes it look fine.
  • 0

#13 _257168

_257168

    GMC Member

  • New Member
  • 8 posts

Posted 17 March 2012 - 08:22 PM

So i have a second question, How do you make a object a enemy ship in my case travel around randomly on the screen but always have to correct facing for the sprite (like my ships facing while shooting) goal is to have a enemy fly around and target the player with pop shots. (This ship can also be hit by the asteroids flying around ect)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users