Rotational direction using cos and sin

Using keyboard input I have achieved rotational and directional movement forward using the cos and sin functions as follows.

self.position.x+*cos(self.rotation)
self.position.y+*sin(self.rotation)

However if I take either one of the lines out it still works.

Can anybody help to point me in the direction to achieve both forward and backward rotational movement using the keyboard as the input device?

Many thanks

Regards

Chris

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2013
    Can you write your equation out all the way?

    For example, are you doing Change Attribute self.position.x to self.position.x*cos(self.rotation)? You listed the operators +* which isn't making sense to me.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • NacMacFeegleNacMacFeegle Member Posts: 11
    Rule
    On key down
    Do
    Move
    Move in direction (equation goes here)
    Move in direction (equation goes here)

    What the +* should do is add the multiplied result.

    Thanks
  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2013

    On key down
    Do
    Move
    Move in direction (equation goes here)
    Move in direction (equation goes here)
    You have two move behaviours that both happen when you press your key ?
    self.position.x+*cos(self.rotation)
    Having a '+' & '*' together will give you an invalid expression.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2013
    Can you post a screenshot of your rules? I was hoping for the actual behavior you are using rather than a general idea. The statement "Move in direction (equation goes here)" could represent a dozen different ways of setting up rules & behaviors in GameSalad. And stacking Move, Move in direction, Move in direction will have unusual results so I'm guessing that's not the order of your behaviors.

    I'm not trying to be a pain... just trying to understand how you have it set up and then help you out.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • NacMacFeegleNacMacFeegle Member Posts: 11
    The utube link below shows 2 examples of achieving this type of motion, the second example is the one I have based the movement on and shows how the equations are used above.



    Many thanks
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Okay, the video is helpful. At 0:57 you show the equations. Now... can you explain what you mean by "both forward and backward rotational movement"?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    Does the attached file help?
  • NacMacFeegleNacMacFeegle Member Posts: 11

    I have zipped up how far I have got, what you should end up with is a square that rotates using the arrow keys left and right, moves forward using the up arrow key in the direction it is now pointing. It’s the back arrow key I can’t get working; I think the process is described as negating.

    https://www.dropbox.com/s/mwf0s7eldphj73k/qk.zip

    Thanks
  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2013
    . . . a square that rotates using the arrow keys left and right, moves forward using the up arrow key in the direction it is now pointing. . . .
    @Chris0000

    Try this:

    http://www.mediafire.com/?44w9vhpmjbzsfym


  • NacMacFeegleNacMacFeegle Member Posts: 11
    Fantastic Socks spot on and many thanks to the other posts.

    Chris
  • SocksSocks London, UK.Member Posts: 12,822
    Fantastic Socks spot on and many thanks to the other posts.

    Chris
    Glad it's the right thing for your needs ! There was no need for sin and cos and all that in the end, I'd always try the simple stuff first.

    :)
Sign In or Register to comment.