Jump to content


Photo

Can anyone help me out?


  • Please log in to reply
5 replies to this topic

#1 Dalton Fox

Dalton Fox

    GMC Member

  • New Member
  • 4 posts
  • Version:GM8

Posted 09 March 2012 - 02:46 AM

Hello, community!
So I have made a ruff 2D physics engine. You play as a tank and there are hills/different terrains you can drive up/down and ramp, etc...
Anyways, the tank and the gun are separate objects and the gun "connects"(follows x,y) to the tank and it has a max pitch and max yaw. When my tank is on flat ground my system for max yaw and pitch work fine, but my tank's angle changes as it drives uphill or downhill the max yaw and pitch don't adjust with the tanks's angle(Therefore I get the gun sticking out underneath the tank when I drive uphill and not aiming down as I drive downhill.)
This is what I have in-place right now for max yaw and pitch of the gun on flat ground:
image_angle=point_direction(x,y,mouse_x,mouse_y)

    if(image_angle >=0 && image_angle <=50)//where my mouse has to be within before my gun will aim towards it.
    {
       image_angle=point_direction(x,y,mouse_x,mouse_y)
    }   
    else if(image_angle <180)//if my mouse is anywhere but within ^^ make it aim up
    {
       image_angle=50
    }
    else //if it is anywhere else aim down
    {
        image_angle=355//makes the gun aim down a little more then straight across
    }
I have tried:
image_angle (>,<,=)obj_player.image_angle+(The number I have after the "<,>,=")

Hoping it would adjust with my angling tank but it had MANY problems. Only thing that fixed was the gun's max pitch as it drove uphill(Meaning it didn't aim through the tank's underbelly) but it only made the gun fling around on flat and inverted land(going down). PLEASE HELP ME! I am not very good at this kind of math.


My sprites(tank and gun) look like this when they are at angle 0:
'''''_____
__|____|=====]
|_________\
(_O__O__O_)

Also, when my mouse is on the left side of the tank the turret flips and the gun changes positions/flips. It is the same code as up there but just with different angles.

*I am using GM8, NOT 8.1*

Edited by Dalton Fox, 09 March 2012 - 02:48 AM.

  • 0

#2 BattleRifle BR55

BattleRifle BR55

    Moo

  • GMC Member
  • 8246 posts
  • Version:GM7

Posted 09 March 2012 - 03:56 AM

Google the "angle_difference()" script.
  • 0

#3 Dalton Fox

Dalton Fox

    GMC Member

  • New Member
  • 4 posts
  • Version:GM8

Posted 09 March 2012 - 03:17 PM

Google the "angle_difference()" script.


So I take the differance between the two angles then add that to my max/min?
Sorry if this is a dumb question, I'm not to great at this...

Edited by Dalton Fox, 09 March 2012 - 03:26 PM.

  • 0

#4 BattleRifle BR55

BattleRifle BR55

    Moo

  • GMC Member
  • 8246 posts
  • Version:GM7

Posted 09 March 2012 - 03:27 PM

If it was what you have, you wouldn't have this problem :P

The script allows the same functionality without any worry on what the angles actually are. Your code uses fixed values in an environment where others are always changing.

Edit - Oh, you edited your post. Essentially, yes, that is what you will need to do.

To comment on another aspect of your post, why not just connect the two objects under one?

Edited by BattleRifle BR55, 09 March 2012 - 03:29 PM.

  • 0

#5 Dalton Fox

Dalton Fox

    GMC Member

  • New Member
  • 4 posts
  • Version:GM8

Posted 09 March 2012 - 07:26 PM

I don't think I know how to make it all one object. i just made it two parts so I have the gun update to the origin of the tank. How would you make it all one object?
Also I plan to have multiple tanks and guns so the basic tank/gun is just the parent for the others.

So I changed my script lines to:
if(angle_difference(image_angle,obj_player.image_angle) (<,>,=) (My max yaw/pitch){}

This only does what I had before but in a glitched way.(It flings around when I aim up, that is besides the point. I can fix that.) It doesn't adjust the gun's yaw and pitch. I probably didn't use it right though.
I guess I am kinda asking how to implement this because I haven't done anything like this before.(Topic should probably be moved)

Edited by Dalton Fox, 09 March 2012 - 10:17 PM.

  • 0

#6 Dalton Fox

Dalton Fox

    GMC Member

  • New Member
  • 4 posts
  • Version:GM8

Posted 11 March 2012 - 02:39 AM

I figured it out! Thank you so much.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users