Search Unity

CharacterController Script for 2D game

Discussion in '2D' started by spawn808, Mar 20, 2021.

  1. spawn808

    spawn808

    Joined:
    Jan 17, 2021
    Posts:
    4
    Hello. I'm trying to write a script for my player and have hit a roadblock. If anyone could point me in the right direction it'd be much appreciated. To recreate, the player is a circle sprite that when you Input.GetKeyDown (spacebar) the circle (ball) jumps vertically. My issue that I can't yet figure out how to make the ball jump at the same angle relative to it's initial position, while rotating. I'd like for it to be where if the ball rotated to where the top is facing left, instead of jumping up, the ball would jump left. With 360 degrees of possible "jumps". Thanks for your time.
     
  2. Stew_79

    Stew_79

    Joined:
    Feb 24, 2021
    Posts:
    36
    Not sure if it will help you but Have a look a recent post I made when I was having issues with rotation
    Trying to rotate an asteroid - Unity Forum
    Also you might want to post your code so people can see your issue :)
     
    spawn808 likes this.
  3. spawn808

    spawn808

    Joined:
    Jan 17, 2021
    Posts:
    4
    Awesome. Thanks for your input. I've just read the thread and will use it to see if I can achieve what I want after work. Even if it doesn't help my issue, learned a lot from the thread on a subject I am not familiar with. My current script is attached.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
     

    Attached Files:

    Stew_79 likes this.
  4. spawn808

    spawn808

    Joined:
    Jan 17, 2021
    Posts:
    4
    Did want to add that I'm not dead set on the code that I posted. That is just a code I've been using that I like that I have been trying to modify to perform the desired action. Any jump script would do, just want to be able to jump at any angle while the player object is rotating, but by one button.
     
  5. spawn808

    spawn808

    Joined:
    Jan 17, 2021
    Posts:
    4
    I feel like I'm over explaining or under explaining so I made a animation.gif to show what I'm going for.
     

    Attached Files: