My ship isnt working

my A & D keys dont make the rocket move when the animation is playing … im using the new input system can anyone help

Hi verse,

Have you already tried to add Debug.Logs to your code to see what is going on during runtime?

Generally, it is advisable to share more information on your project, the problem, and what you tried to solve the it. Otherwise, it might be difficult or even impossible to help you.


See also:

Like @Nina said, we need more info. How did you set up the keys in the input system? How are you reacting to those inputs?

hi, i am using the new 2023.2 version of unity, what i used to setup the movement is Vector2 keybindings, action type is value, control type is any. i added some debug keys as well heres my script:

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

public class InputController : MonoBehaviour
{
[SerializeField] InputAction movement;
[SerializeField] float speed = 10f;
// Start is called before the first frame update
void Start()
{

}

private void OnEnable()
{
    movement.Enable();
}
 private void OnDisable()
{
    movement.Disable();
}
void Update()
{

    float xThrow = movement.ReadValue<Vector2>().x;
    float yThrow = movement.ReadValue<Vector2>().y;
    Debug.Log(xThrow);
    Debug.Log(yThrow);

    float xOffset = xThrow * Time.deltaTime * speed;
    float newXPos = transform.localPosition.x + xOffset;
    
    float yOffset = yThrow * Time.deltaTime * speed;
    float newYPos = transform.localPosition.y + yOffset;

    transform.localPosition = new Vector3 (newXPos, newYPos, transform.localPosition.z);
}

}

From what I see, your thread is tagged with ‘14_aa_uy3’, which refers to the Argon Assault section in the Complete Unity 3D course. Your code seems be refer to the Argon Assault section, too. We do not have any rocket in that game. The rocket is in the Project Boost section. So my question is: Does your problem refer to Argon Assault, where we animate the player game object, or to Project Boost, where we do not animate the player game object?

In your code, you have these two lines:

Debug.Log(xThrow);
Debug.Log(yThrow);

What is the output in the console at runtime? Do you get values higher or lower than 0 when pressing the input keys?

If so, check the Timeline animation (given you are in the Argon Assault section). Make sure that only the PlayerRig is animated, not the PlayerShip (= the child of PlayerRig). Only the PlayerShip may have the InputController component assigned, not hte PlayerRig (= the animated game object).

If you move the PlayerShip via code and animate it, the animation overrides the values that have been applied by your code.

my code refers to Argon assault. and i get values of 1 to -1, the animator component is on PlayerRig and the PlayerShip has the InputController added

Since you seem to get values ranging from -1 to 1 in your console, there very likely is no problem with the user input, which is good to know. :slight_smile:

The animator component does not determine which game object is animated, thus it is irrelevant for this problem. The animation animates a game object. If you want to figure out which one it is, you need to check the animation.

i checked the timeline turns out PlayerShip was being animated, the problem is now fixed. Thank you so much for helping me, i really appreciate

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms