0

There is a static mesh bot in C++ that moves forward. Through Ray Casting, he tracks obstacles in front of him and if he finds them, he must turn to the side. Direct access via getactorrotation () rotates the bot around its local axis. question: how do i make the bot rotate in world coordinates?

neoluna
  • 17
  • 4
  • GetActorRotation does return a rotator in world space so I don't really understand your question. Perhaps a problem description with sample code would help? – George Dec 20 '20 at 14:17
  • Getactorrotation () returns the rotation of the object around itself, while the motion vector remains the same. I'm really confused about these vector-rotator manipulations... Here is the code of what rotatevector () accepts and returns. There were many attempts to add/increase/multiply the return value to the axis of motion, but alas.. In bp logic, everything looks simple. `const FRotator Rotate(0, 0, 20);` `//the result is a vector rotated by rotate FVector Vector = Rotate.RotateVector(FVector(0, 0, 1));` – neoluna Dec 21 '20 at 06:02
  • Okay so I assume the bot is rotating, it's just their velocity is incorrect? Then this depends on how you're adding velocity, if you're using the standard controller->character movement setup, then you want to set your bot controller's control rotation. Alternatively you could just set your bot's velocity instead, if memory serves rotation follows velocity by default (Not 100% on this solution though as I've only ever used heavily modified movement code in anger). – George Dec 21 '20 at 11:26
  • Movement: `FVector Direction = GetActorLocation(); Direction.X += 1; SetActorLocation(Direction);` In BP logic with a Character, it looks simple, there RotateVector () changes the Direction that goes to RotateVector().. But i just have a cube that moves in increments of X. It turns out that you need to rotate the X-axis of the bot itself and direct the movement already in the new direction of the X-axis, but the bot still moves along the world X-axis, no matter how it is rotated. I'm really stuck.. – neoluna Dec 21 '20 at 13:14
  • Ah, that's because you're always moving along world axes. Try something like `const float Speed = 30.f; const float MoveDelta = DeltaTime * Speed; const FVector Vel = GetActorForwardVector() * MoveDelta; SetActorLocation(GetActorLocation() + Vel);`. – George Dec 21 '20 at 13:40
  • Thanks for the help, but alas, it doesn't work. – neoluna Dec 21 '20 at 14:05

0 Answers0